@@ -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