Skip to content

Commit

Permalink
Also add a test for TypedDict classes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Nov 9, 2023
1 parent e3b703d commit 7ccff63
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8101,6 +8101,23 @@ class T4(TypedDict, Generic[S]): pass
self.assertEqual(klass.__optional_keys__, set())
self.assertIsInstance(klass(), dict)

def test_setname_called_on_things_in_class_namespace(self):
class CustomException(Exception): pass

class Annoying:
def __set_name__(self, owner, name):
raise CustomException("Cannot do that!")

with self.assertRaisesRegex(CustomException, "Cannot do that!") as cm:
class Foo(TypedDict):
attr = Annoying()

expected_note = (
"Error calling __set_name__ on 'Annoying' instance "
"'attr' in 'Foo'"
)
self.assertIn(expected_note, cm.exception.__notes__)


class RequiredTests(BaseTestCase):

Expand Down

0 comments on commit 7ccff63

Please sign in to comment.