Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.13] gh-144169: Fix three crashes in AST objects with non-str kwargs (GH-144178)#144260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletionsLib/test/test_ast/test_ast.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3141,6 +3141,27 @@ class _AllFieldTypes(ast.AST):
self.assertIs(obj.a, None)
self.assertEqual(obj.b, [])

def test_non_str_kwarg(self):
warn_msg = "got an unexpected keyword argument <object object"
with (
self.assertRaises(TypeError),
self.assertWarnsRegex(DeprecationWarning, warn_msg),
):
ast.Name(**{object(): 'y'})

class FakeStr:
def __init__(self, value):
self.value = value

def __hash__(self):
return hash(self.value)

def __eq__(self, other):
return isinstance(other, str) and self.value == other

with self.assertRaisesRegex(TypeError, "got multiple values for argument"):
ast.Name("x", **{FakeStr('id'): 'y'})


@support.cpython_only
class ModuleStateTests(unittest.TestCase):
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Fix three crashes when non-string keyword arguments are supplied to objects
in the :mod:`ast` module.
4 changes: 2 additions & 2 deletionsParser/asdl_c.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -939,7 +939,7 @@ def visitModule(self, mod):
}
if (p == 0) {
PyErr_Format(PyExc_TypeError,
"%.400s got multiple values for argument'%U'",
"%.400s got multiple values for argument%R",
Py_TYPE(self)->tp_name, key);
res = -1;
goto cleanup;
Expand All@@ -962,7 +962,7 @@ def visitModule(self, mod):
else if (contains == 0) {
if (PyErr_WarnFormat(
PyExc_DeprecationWarning, 1,
"%.400s.__init__ got an unexpected keyword argument'%U'. "
"%.400s.__init__ got an unexpected keyword argument%R. "
"Support for arbitrary keyword arguments is deprecated "
"and will be removed in Python 3.15.",
Py_TYPE(self)->tp_name, key
Expand Down
4 changes: 2 additions & 2 deletionsPython/Python-ast.c
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Loading

[8]ページ先頭

©2009-2026 Movatter.jp