Skip to content

Commit 7ccff63

Browse files
committed
Also add a test for TypedDict classes
1 parent e3b703d commit 7ccff63

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Lib/test/test_typing.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8101,6 +8101,23 @@ class T4(TypedDict, Generic[S]): pass
81018101
self.assertEqual(klass.__optional_keys__, set())
81028102
self.assertIsInstance(klass(), dict)
81038103

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+
81048121

81058122
class RequiredTests(BaseTestCase):
81068123

0 commit comments

Comments
 (0)