]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-92106: Add test that subscription works on arbitrary TypedDicts (#92176)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 2 May 2022 22:38:39 +0000 (01:38 +0300)
committerGitHub <noreply@github.com>
Mon, 2 May 2022 22:38:39 +0000 (16:38 -0600)
Lib/test/test_typing.py

index 88be2850acb1cc8aaeb55b9b1d5aecd50347c889..cb7ca3610b06a66082e690240aecf33c73e9e938 100644 (file)
@@ -6024,6 +6024,19 @@ class TypedDictTests(BaseTestCase):
             {'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):