Skip to content

Commit

Permalink
pythongh-126105: Fix crash in ast module, when ._fields is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Oct 29, 2024
1 parent 9b14083 commit 4186e14
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
17 changes: 17 additions & 0 deletions Lib/test/test_ast/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ def test_AST_objects(self):
# "ast.AST constructor takes 0 positional arguments"
ast.AST(2)

def test_AST_fields_NULL_check(self):
# See: https://github.com/python/cpython/issues/126105
old_value = ast.AST._fields

def cleanup():
ast.AST._fields = old_value
self.addCleanup(cleanup)

del ast.AST._fields

msg = 'AST has no fields'
# Both examples used to crash:
with self.assertRaisesRegex(TypeError, msg):
ast.AST(arg1=123)
with self.assertRaisesRegex(TypeError, msg):
ast.AST()

def test_AST_garbage_collection(self):
class X:
pass
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a crash in :mod:`ast` when ``_fields`` attribute is deleted.
18 changes: 10 additions & 8 deletions Python/Python-ast.c

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

0 comments on commit 4186e14

Please sign in to comment.