Skip to content

gh-92106: Forbid specialization of TypedDict types #92116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5811,6 +5811,8 @@ def test_typeddict_errors(self):
isinstance(jim, Emp)
with self.assertRaises(TypeError):
issubclass(dict, Emp)
with self.assertRaises(TypeError):
Emp[int, str]
with self.assertRaises(TypeError):
TypedDict('Hi', [('x', int)], y=int)

Expand Down
1 change: 1 addition & 0 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2883,6 +2883,7 @@ def __new__(cls, name, bases, ns, total=True):
tp_dict.__optional_keys__ = frozenset(optional_keys)
if not hasattr(tp_dict, '__total__'):
tp_dict.__total__ = total
tp_dict.__class_getitem__ = None
return tp_dict

__call__ = dict # static method
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:class:`typing.TypedDict` types are non-generic by default. Subscripting
them raises now TypeError.