]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-92106: Add test that subscription works on arbitrary TypedDicts (GH-92176)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 3 May 2022 00:39:07 +0000 (17:39 -0700)
committerGitHub <noreply@github.com>
Tue, 3 May 2022 00:39:07 +0000 (17:39 -0700)
(cherry picked from commit 81fb3548be5a18bf40a6f4505a02cc7fb72c9c34)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_typing.py

index 779e1758d51d8a904290fed7611a80d2c9ee2a1c..111a207dd10b3ccfb7d26b163306f903ca3e94e3 100644 (file)
@@ -4485,6 +4485,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 IOTests(BaseTestCase):