summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ast.py
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2024-07-11 15:51:32 (GMT)
committerGitHub <noreply@github.com>2024-07-11 15:51:32 (GMT)
commit38c4028dd9aeeeb1fe4ba1444307e3f06fc63aa0 (patch)
tree11c6a654355b1843071221024ccd39c615b47b54 /Lib/test/test_ast.py
parent3b5f8d256c534e9b2baa64ec151da0d590213667 (diff)
downloadcpython-38c4028dd9aeeeb1fe4ba1444307e3f06fc63aa0.zip
cpython-38c4028dd9aeeeb1fe4ba1444307e3f06fc63aa0.tar.gz
cpython-38c4028dd9aeeeb1fe4ba1444307e3f06fc63aa0.tar.bz2
[3.13] gh-121332: Make AST node constructor check _attributes instead of hardcoding attributes (GH-121334) (#121625)
(cherry picked from commit 58e8cf2bb61f82df9eabd1209fe5e3d146e4c8cd)
Diffstat (limited to 'Lib/test/test_ast.py')
-rw-r--r--Lib/test/test_ast.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 93bd5de..744cd23 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -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',)