From 387aa6cc4c86611020984e63dc71a76142739c46 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 2 May 2022 21:44:29 +0300 Subject: [PATCH] gh-92106: Add test that subscription works on arbitrary TypedDicts --- Lib/test/test_typing.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 88be2850acb1cc..cb7ca3610b06a6 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -6024,6 +6024,19 @@ def test_get_type_hints(self): {'a': typing.Optional[int], 'b': int} ) + def test_non_generic_subscript(self): + # For backward compatibility, subscription works + # on arbitrary TypedDict types. + class TD(TypedDict): + a: T + A = TD[int] + self.assertEqual(A.__origin__, TD) + self.assertEqual(A.__parameters__, ()) + self.assertEqual(A.__args__, (int,)) + a = A(a = 1) + self.assertIs(type(a), dict) + self.assertEqual(a, {'a': 1}) + class RequiredTests(BaseTestCase):