Skip to content

Commit 309bc4e

Browse files
committed
Add test for setting dynamic attributes
1 parent 85986cd commit 309bc4e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Lib/test/test_ast/test_ast.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,18 @@ def test_field_attr_existence(self):
417417
if isinstance(x, ast.AST):
418418
self.assertIs(type(x._fields), tuple)
419419

420+
def test_dynamic_attr(self):
421+
for name, item in ast.__dict__.items():
422+
# constructor has a different signature
423+
if name == 'Index':
424+
continue
425+
if self._is_ast_node(name, item):
426+
x = self._construct_ast_class(item)
427+
# Random attribute assignment is allowed
428+
x.foo = 5
429+
self.assertEqual(x.foo, 5)
430+
del x.foo
431+
420432
def _construct_ast_class(self, cls):
421433
kwargs = {}
422434
for name, typ in cls.__annotations__.items():

0 commit comments

Comments
 (0)