Skip to content

Commit adc06cd

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 5f40cb8 commit adc06cd

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
@@ -4485,6 +4485,19 @@ def test_get_type_hints(self):
44854485
{'a': typing.Optional[int], 'b': int}
44864486
)
44874487

4488+
def test_non_generic_subscript(self):
4489+
# For backward compatibility, subscription works
4490+
# on arbitrary TypedDict types.
4491+
class TD(TypedDict):
4492+
a: T
4493+
A = TD[int]
4494+
self.assertEqual(A.__origin__, TD)
4495+
self.assertEqual(A.__parameters__, ())
4496+
self.assertEqual(A.__args__, (int,))
4497+
a = A(a = 1)
4498+
self.assertIs(type(a), dict)
4499+
self.assertEqual(a, {'a': 1})
4500+
44884501

44894502
class IOTests(BaseTestCase):
44904503

0 commit comments

Comments
 (0)