From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 3 May 2022 01:05:49 +0000 (-0700) Subject: gh-92106: Add test that subscription works on arbitrary TypedDicts (GH-92176) X-Git-Tag: v3.9.13~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e55730e3f0a0c8c1b73037011e4b00dd7bd7f69;p=thirdparty%2FPython%2Fcpython.git gh-92106: Add test that subscription works on arbitrary TypedDicts (GH-92176) (cherry picked from commit 81fb3548be5a18bf40a6f4505a02cc7fb72c9c34) Co-authored-by: Serhiy Storchaka --- diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 08eddb095d56..3fec59a87914 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -4076,6 +4076,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):