Skip to content

Commit fa270ff

Browse files
Misc updates from review
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent 48267a3 commit fa270ff

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

Doc/whatsnew/3.15.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ Removed
421421
ast
422422
---
423423

424-
* The constructors of node types in the :mod:`ast` module now raise a
424+
* The constructors of AST node types in the :mod:`ast` module now raise a
425425
:exc:`TypeError` when a required argument is omitted or when a
426426
keyword-argument that does not map to a field on the AST node is passed.
427427
These cases had previously raised a :exc:`DeprecationWarning` since Python 3.13.

Lib/test/test_ast/test_ast.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ def test_nodeclasses(self):
545545
# Random attribute allowed too
546546
x.foobarbaz = 5
547547
self.assertEqual(x.foobarbaz, 5)
548+
self.assertEqual(x._fields, ('left', 'op', 'right'))
548549

549550
x = ast.BinOp(1, 2, 3)
550551
self.assertEqual(x.left, 1)
@@ -570,7 +571,8 @@ def test_nodeclasses(self):
570571
self.assertEqual(x.lineno, 0)
571572

572573
# Random kwargs are not allowed
573-
with self.assertRaisesRegex(TypeError, "unexpected keyword argument 'foobarbaz'"):
574+
msg = "ast.BinOp.__init__ got an unexpected keyword argument 'foobarbaz'"
575+
with self.assertRaisesRegex(TypeError, re.escape(msg)):
574576
x = ast.BinOp(1, 2, 3, foobarbaz=42)
575577

576578
def test_no_fields(self):
@@ -3271,17 +3273,17 @@ class MyAttrs(ast.AST):
32713273
self.assertEqual(obj.a, 1)
32723274
self.assertEqual(obj.b, 2)
32733275

3274-
with self.assertRaisesRegex(TypeError,
3275-
r"MyAttrs.__init__ got an unexpected keyword argument 'c'"):
3276+
msg = "MyAttrs.__init__ got an unexpected keyword argument 'c'"
3277+
with self.assertRaisesRegex(TypeError, re.escape(msg)):
32763278
obj = MyAttrs(c=3)
32773279

32783280
def test_fields_and_types_no_default(self):
32793281
class FieldsAndTypesNoDefault(ast.AST):
32803282
_fields = ('a',)
32813283
_field_types = {'a': int}
32823284

3283-
with self.assertRaisesRegex(TypeError,
3284-
r"FieldsAndTypesNoDefault\.__init__ missing 1 required positional argument: 'a'"):
3285+
msg = "FieldsAndTypesNoDefault.__init__ missing 1 required positional argument: 'a'"
3286+
with self.assertRaisesRegex(TypeError, re.escape(msg)):
32853287
obj = FieldsAndTypesNoDefault()
32863288

32873289
obj = FieldsAndTypesNoDefault(a=1)
@@ -3294,7 +3296,8 @@ class MoreFieldsThanTypes(ast.AST):
32943296
a: int | None = None
32953297
b: int | None = None
32963298

3297-
with self.assertRaisesRegex(TypeError, "Field 'b' is missing"):
3299+
msg = "Field 'b' is missing from test.test_ast.test_ast.ASTConstructorTests.test_incomplete_field_types.<locals>.MoreFieldsThanTypes._field_types"
3300+
with self.assertRaisesRegex(TypeError, re.escape(msg)):
32983301
obj = MoreFieldsThanTypes()
32993302

33003303
obj = MoreFieldsThanTypes(a=1, b=2)

0 commit comments

Comments
 (0)