mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.13] gh-121332: Make AST node constructor check _attributes instead of hardcoding attributes (GH-121334) (#121625)
(cherry picked from commit 58e8cf2bb6
)
This commit is contained in:
parent
3b5f8d256c
commit
38c4028dd9
4 changed files with 66 additions and 28 deletions
|
@ -3148,6 +3148,18 @@ class ASTConstructorTests(unittest.TestCase):
|
|||
obj = FieldsAndTypes(a=1)
|
||||
self.assertEqual(obj.a, 1)
|
||||
|
||||
def test_custom_attributes(self):
|
||||
class MyAttrs(ast.AST):
|
||||
_attributes = ("a", "b")
|
||||
|
||||
obj = MyAttrs(a=1, b=2)
|
||||
self.assertEqual(obj.a, 1)
|
||||
self.assertEqual(obj.b, 2)
|
||||
|
||||
with self.assertWarnsRegex(DeprecationWarning,
|
||||
r"MyAttrs.__init__ got an unexpected keyword argument 'c'."):
|
||||
obj = MyAttrs(c=3)
|
||||
|
||||
def test_fields_and_types_no_default(self):
|
||||
class FieldsAndTypesNoDefault(ast.AST):
|
||||
_fields = ('a',)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue