From 921c65304e069360fdc5dc4977525d34f514982a Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Tue, 19 Nov 2024 22:50:42 -0800 Subject: [PATCH] Annotate TypedDict as _SpecialForm rather than object. (#12985) * Annotate TypedDict as _SpecialForm rather than object. Let's see if this works... * Get typing_extensions.TypedDict as well, try to fix tests. * Import typing_extensions.TypedDict, delete _SpecialForm.__getitem__. * Back out deletion of _SpecialForm.__getitem__. --- stdlib/@tests/stubtest_allowlists/common.txt | 1 + stdlib/typing.pyi | 3 +-- stdlib/typing_extensions.pyi | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index 055e0d7d3..3abe00aa8 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -464,6 +464,7 @@ typing_extensions\.ParamSpec.* typing(_extensions)?\.Generic typing\.Protocol typing(_extensions)?\._TypedDict +typing(_extensions)?\.TypedDict typing._Final typing._Final.__init_subclass__ diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index f92936ec3..81755af9e 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -213,8 +213,7 @@ Tuple: _SpecialForm Final: _SpecialForm Literal: _SpecialForm -# TypedDict is a (non-subscriptable) special form. -TypedDict: object +TypedDict: _SpecialForm if sys.version_info >= (3, 11): Self: _SpecialForm diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 8a4f3abd1..a6b606e6b 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -58,6 +58,7 @@ from typing import ( # noqa: Y022,Y037,Y038,Y039 TextIO as TextIO, Tuple as Tuple, Type as Type, + TypedDict as TypedDict, Union as Union, ValuesView as ValuesView, _Alias, @@ -255,9 +256,6 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): # supposedly incompatible definitions of `__ior__` and `__or__`: def __ior__(self, value: Self, /) -> Self: ... # type: ignore[misc] -# TypedDict is a (non-subscriptable) special form. -TypedDict: object - OrderedDict = _Alias() def get_type_hints(