We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e3b703d commit 7ccff63Copy full SHA for 7ccff63
1 file changed
Lib/test/test_typing.py
@@ -8101,6 +8101,23 @@ class T4(TypedDict, Generic[S]): pass
8101
self.assertEqual(klass.__optional_keys__, set())
8102
self.assertIsInstance(klass(), dict)
8103
8104
+ def test_setname_called_on_things_in_class_namespace(self):
8105
+ class CustomException(Exception): pass
8106
+
8107
+ class Annoying:
8108
+ def __set_name__(self, owner, name):
8109
+ raise CustomException("Cannot do that!")
8110
8111
+ with self.assertRaisesRegex(CustomException, "Cannot do that!") as cm:
8112
+ class Foo(TypedDict):
8113
+ attr = Annoying()
8114
8115
+ expected_note = (
8116
+ "Error calling __set_name__ on 'Annoying' instance "
8117
+ "'attr' in 'Foo'"
8118
+ )
8119
+ self.assertIn(expected_note, cm.exception.__notes__)
8120
8121
8122
class RequiredTests(BaseTestCase):
8123
0 commit comments