@@ -1004,25 +1004,22 @@ class AClassWithMetaclass(metaclass=AMeta):
10041004@cpython_only
10051005class TestIncorrectNumberOfPositionalArgs (unittest .TestCase ):
10061006 @contextlib .contextmanager
1007- def assert_type_error_and_msg_in (self , message : str ):
1007+ def assert_type_error_and_msg_in (self , message ):
10081008 with self .assertRaises (TypeError ) as cm :
10091009 yield cm
10101010 self .assertIn (message , str (cm .exception ))
10111011
10121012 def test_too_many_positional_with_defaults_suggests_missing_self (self ):
1013- """A method with defaults that omits self should still get the hint."""
10141013 msg = ".method_two_args() takes from 0 to 2 positional arguments but 3 were given. Did you forget the 'self' parameter in the function definition?"
10151014 with self .assert_type_error_and_msg_in (msg ):
10161015 A ().method_two_args ("woof" , "loud" )
10171016
10181017 def test_too_many_positional_but_missing_self_no_args (self ):
1019- """A zero-argument method called through an instance should get the hint."""
10201018 msg = "takes 0 positional arguments but 1 was given. Did you forget the 'self' parameter in the function definition?"
10211019 with self .assert_type_error_and_msg_in (msg ):
10221020 A ().method_zero_arg ()
10231021
10241022 def test_too_many_positional_but_missing_self (self ):
1025- """A bound instance method missing self should get the targeted hint."""
10261023 msg = ".method_one_arg() takes 1 positional argument but 2 were given. Did you forget the 'self' parameter in the function definition?"
10271024 with self .assert_type_error_and_msg_in (msg ):
10281025 A ().method_one_arg ("quiet" )
@@ -1048,62 +1045,53 @@ def test_multiple_values(self):
10481045 A ().method_two_args ("quiet" , "low" , arg1 = "oops" )
10491046
10501047 def test_unbound_method_with_self_keeps_missing_argument_error (self ):
1051- """Calling an unbound method without self should keep the missing-arg error."""
10521048 msg = ".method_one_arg() missing 1 required positional argument: 'arg1'"
10531049 with self .assert_type_error_and_msg_in (msg ):
10541050 A .method_one_arg ()
10551051
10561052 def test_classmethod_missing_cls_does_not_suggest_missing_self (self ):
1057- """A classmethod missing cls conceptually should not suggest self."""
10581053 msg = ".classmethod_one_arg() takes 1 positional argument but 2 were given"
10591054 with self .assert_type_error_and_msg_in (msg ) as cm :
10601055 A .classmethod_one_arg ("arg1" )
10611056 self .assertNotIn ("Did you forget" , str (cm .exception ))
10621057
10631058 def test_classmethod_missing_cls_via_instance_does_not_suggest_missing_self (self ):
1064- """A classmethod called through an instance should not suggest self."""
10651059 msg = ".classmethod_one_arg() takes 1 positional argument but 2 were given"
10661060 with self .assert_type_error_and_msg_in (msg ) as cm :
10671061 A ().classmethod_one_arg ("poodle" )
10681062 self .assertNotIn ("Did you forget" , str (cm .exception ))
10691063
10701064 def test_staticmethod_too_many_args_does_not_suggest_missing_self (self ):
1071- """A staticmethod with too many arguments should not suggest self."""
10721065 msg = ".static_one_arg() takes 1 positional argument but 2 were given"
10731066 with self .assert_type_error_and_msg_in (msg ) as cm :
10741067 A .static_one_arg (1 , 2 )
10751068 self .assertNotIn ("Did you forget" , str (cm .exception ))
10761069
10771070 def test_staticmethod_too_many_args_via_instance_does_not_suggest_missing_self (self ):
1078- """A staticmethod called through an instance should not suggest self."""
10791071 msg = ".static_one_arg() takes 1 positional argument but 2 were given"
10801072 with self .assert_type_error_and_msg_in (msg ) as cm :
10811073 A ().static_one_arg (1 , 2 )
10821074 self .assertNotIn ("Did you forget" , str (cm .exception ))
10831075
10841076 def test_metaclass_missing_receiver_does_not_suggest_missing_self (self ):
1085- """A metaclass receiver error should not suggest an instance self."""
10861077 msg = "AMeta.method_one_arg() takes 1 positional argument but 2 were given"
10871078 with self .assert_type_error_and_msg_in (msg ) as cm :
10881079 AClassWithMetaclass .method_one_arg ("standard" )
10891080 self .assertNotIn ("Did you forget" , str (cm .exception ))
10901081
10911082 def test_metaclass_method_too_many_args_does_not_suggest_missing_self (self ):
1092- """A metaclass method with too many arguments should not suggest self."""
10931083 msg = "AMeta.method_two_arg() takes 2 positional arguments but 3 were given"
10941084 with self .assert_type_error_and_msg_in (msg ) as cm :
10951085 AClassWithMetaclass .method_two_arg ("trail" , "river" )
10961086 self .assertNotIn ("Did you forget" , str (cm .exception ))
10971087
10981088 def test_metaclass_classmethod_does_not_suggest_missing_self (self ):
1099- """A classmethod on a metaclass should not suggest instance self."""
11001089 msg = "AMeta.classmethod_one_arg() takes 1 positional argument but 2 were given"
11011090 with self .assert_type_error_and_msg_in (msg ) as cm :
11021091 AClassWithMetaclass .classmethod_one_arg ("standard" )
11031092 self .assertNotIn ("Did you forget" , str (cm .exception ))
11041093
11051094 def test_metaclass_staticmethod_does_not_suggest_missing_self (self ):
1106- """A staticmethod on a metaclass should not suggest instance self."""
11071095 msg = "AMeta.static_one_arg() takes 1 positional argument but 2 were given"
11081096 with self .assert_type_error_and_msg_in (msg ) as cm :
11091097 AClassWithMetaclass .static_one_arg ("show" , "working" )
0 commit comments