@@ -459,8 +459,7 @@ def test_field_attr_writable(self):
459459
460460 def test_classattrs (self ):
461461 msg = "ast.Constant.__init__ missing 1 required positional argument: 'value'"
462- with self .assertRaisesRegex (TypeError , re .escape (msg )):
463- x = ast .Constant ()
462+ self .assertRaisesRegex (TypeError , re .escape (msg ), ast .Constant )
464463
465464 x = ast .Constant (42 )
466465 self .assertEqual (x ._fields , ('value' , 'kind' ))
@@ -531,8 +530,7 @@ def test_module(self):
531530 def test_nodeclasses (self ):
532531 # Zero arguments constructor is not allowed
533532 msg = "ast.BinOp.__init__ missing 3 required positional arguments: 'left', 'op', and 'right'"
534- with self .assertRaisesRegex (TypeError , re .escape (msg )):
535- x = ast .BinOp ()
533+ self .assertRaisesRegex (TypeError , re .escape (msg ), ast .BinOp )
536534
537535 n1 = ast .Constant (1 )
538536 n3 = ast .Constant (3 )
@@ -574,7 +572,7 @@ def test_nodeclasses(self):
574572 # Random kwargs are not allowed
575573 msg = "ast.BinOp.__init__ got an unexpected keyword argument 'foobarbaz'"
576574 with self .assertRaisesRegex (TypeError , re .escape (msg )):
577- x = ast .BinOp (1 , 2 , 3 , foobarbaz = 42 )
575+ ast .BinOp (1 , 2 , 3 , foobarbaz = 42 )
578576
579577 def test_no_fields (self ):
580578 # this used to fail because Sub._fields was None
@@ -3214,7 +3212,7 @@ def test_FunctionDef(self):
32143212 self .assertEqual (args .posonlyargs , [])
32153213 msg = "ast.FunctionDef.__init__ missing 1 required positional argument: 'name'"
32163214 with self .assertRaisesRegex (TypeError , re .escape (msg )):
3217- node = ast .FunctionDef (args = args )
3215+ ast .FunctionDef (args = args )
32183216
32193217 node = ast .FunctionDef (name = 'foo' , args = args )
32203218 self .assertEqual (node .name , 'foo' )
@@ -3234,8 +3232,7 @@ def test_expr_context(self):
32343232 self .assertIsInstance (name3 .ctx , ast .Del )
32353233
32363234 msg = "ast.Name.__init__ missing 1 required positional argument: 'id'"
3237- with self .assertRaisesRegex (TypeError , re .escape (msg )):
3238- name3 = ast .Name ()
3235+ self .assertRaisesRegex (TypeError , re .escape (msg ), ast .Name )
32393236
32403237 def test_custom_subclass_with_no_fields (self ):
32413238 class NoInit (ast .AST ):
@@ -3276,16 +3273,15 @@ class MyAttrs(ast.AST):
32763273
32773274 msg = "MyAttrs.__init__ got an unexpected keyword argument 'c'"
32783275 with self .assertRaisesRegex (TypeError , re .escape (msg )):
3279- obj = MyAttrs (c = 3 )
3276+ MyAttrs (c = 3 )
32803277
32813278 def test_fields_and_types_no_default (self ):
32823279 class FieldsAndTypesNoDefault (ast .AST ):
32833280 _fields = ('a' ,)
32843281 _field_types = {'a' : int }
32853282
32863283 msg = "FieldsAndTypesNoDefault.__init__ missing 1 required positional argument: 'a'"
3287- with self .assertRaisesRegex (TypeError , re .escape (msg )):
3288- obj = FieldsAndTypesNoDefault ()
3284+ self .assertRaisesRegex (TypeError , re .escape (msg ), FieldsAndTypesNoDefault )
32893285
32903286 obj = FieldsAndTypesNoDefault (a = 1 )
32913287 self .assertEqual (obj .a , 1 )
@@ -3298,8 +3294,7 @@ class MoreFieldsThanTypes(ast.AST):
32983294 b : int | None = None
32993295
33003296 msg = "Field 'b' is missing from .*\.MoreFieldsThanTypes\._field_types"
3301- with self .assertRaisesRegex (TypeError , msg ):
3302- obj = MoreFieldsThanTypes ()
3297+ self .assertRaisesRegex (TypeError , msg , MoreFieldsThanTypes )
33033298
33043299 obj = MoreFieldsThanTypes (a = 1 , b = 2 )
33053300 self .assertEqual (obj .a , 1 )
0 commit comments