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

(cherry picked from commit 81fb3548be)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-05-02 17:39:07 -07:00 committed by GitHub
parent 5f40cb85c2
commit adc06cd2d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4485,6 +4485,19 @@ class TypedDictTests(BaseTestCase):
{'a': typing.Optional[int], 'b': int} {'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): class IOTests(BaseTestCase):