[Python-checkins] gh-92106: Add test that subscription works on arbitrary TypedDicts (#92176)

JelleZijlstra webhook-mailer at python.org
Mon May 2 18:38:49 EDT 2022


https://github.com/python/cpython/commit/81fb3548be5a18bf40a6f4505a02cc7fb72c9c34
commit: 81fb3548be5a18bf40a6f4505a02cc7fb72c9c34
branch: main
author: Serhiy Storchaka <storchaka at gmail.com>
committer: JelleZijlstra <jelle.zijlstra at gmail.com>
date: 2022-05-02T16:38:39-06:00
summary:

gh-92106: Add test that subscription works on arbitrary TypedDicts (#92176)

files:
M Lib/test/test_typing.py

diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 88be2850acb1c..cb7ca3610b06a 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):
 



More information about the Python-checkins mailing list