From a4c3efa1a6e5b4f844e9a1e5e47503ef1ee3d1fc Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 1 May 2022 16:59:28 +0300 Subject: [PATCH] gh-92106: Forbid specialization of TypedDict types --- Lib/test/test_typing.py | 2 ++ Lib/typing.py | 1 + .../next/Library/2022-05-01-16-58-31.gh-issue-92106.qjt1Gq.rst | 2 ++ 3 files changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-05-01-16-58-31.gh-issue-92106.qjt1Gq.rst diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 88be2850acb1cc..7f36a421a58595 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -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) diff --git a/Lib/typing.py b/Lib/typing.py index 35deb32220eb88..c9c190f4a1b4ff 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -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 diff --git a/Misc/NEWS.d/next/Library/2022-05-01-16-58-31.gh-issue-92106.qjt1Gq.rst b/Misc/NEWS.d/next/Library/2022-05-01-16-58-31.gh-issue-92106.qjt1Gq.rst new file mode 100644 index 00000000000000..941ebeb84adb69 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-05-01-16-58-31.gh-issue-92106.qjt1Gq.rst @@ -0,0 +1,2 @@ +:class:`typing.TypedDict` types are non-generic by default. Subscripting +them raises now TypeError.