Skip to content

Commit 7e55730

Browse files
gh-92106: Add test that subscription works on arbitrary TypedDicts (GH-92176)
(cherry picked from commit 81fb354) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 51b885a commit 7e55730

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Lib/test/test_typing.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4076,6 +4076,19 @@ def test_get_type_hints(self):
40764076
{'a': typing.Optional[int], 'b': int}
40774077
)
40784078

4079+
def test_non_generic_subscript(self):
4080+
# For backward compatibility, subscription works
4081+
# on arbitrary TypedDict types.
4082+
class TD(TypedDict):
4083+
a: T
4084+
A = TD[int]
4085+
self.assertEqual(A.__origin__, TD)
4086+
self.assertEqual(A.__parameters__, ())
4087+
self.assertEqual(A.__args__, (int,))
4088+
a = A(a = 1)
4089+
self.assertIs(type(a), dict)
4090+
self.assertEqual(a, {'a': 1})
4091+
40794092

40804093
class IOTests(BaseTestCase):
40814094

0 commit comments

Comments
 (0)