From 1d5d4aa0b4ebbd8c5166b613aee2158f6d5e1333 Mon Sep 17 00:00:00 2001 From: KotlinIsland Date: Fri, 18 Mar 2022 00:01:16 +1000 Subject: [PATCH] add `typing._SubscriptableSpecialForm` and use it to fix various special forms --- stdlib/typing.pyi | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 457ad21b72d2..d21c42a93e40 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -486,11 +486,14 @@ _promote = object() # N.B. Keep this definition in sync with typing_extensions._SpecialForm @_final class _SpecialForm: - def __getitem__(self, parameters: Any) -> object: ... if sys.version_info >= (3, 10): def __or__(self, other: Any) -> _SpecialForm: ... def __ror__(self, other: Any) -> _SpecialForm: ... + +class _SubscriptableSpecialForm(_SpecialForm): # type: ignore + def __getitem__(self, parameters: Any) -> object: ... + _F = TypeVar("_F", bound=Callable[..., Any]) _P = _ParamSpec("_P") _T = TypeVar("_T") @@ -503,26 +506,26 @@ def overload(func: _F) -> _F: ... # Otherwise, flake8 erroneously flags them as undefined. # `_SpecialForm` objects in typing.py that are not used elswhere in the same file # do not need the default value assignment. -Union: _SpecialForm = ... -Generic: _SpecialForm = ... +Union: _SubscriptableSpecialForm = ... +Generic: _SubscriptableSpecialForm = ... # Protocol is only present in 3.8 and later, but mypy needs it unconditionally -Protocol: _SpecialForm = ... -Callable: _SpecialForm = ... -Type: _SpecialForm = ... +Protocol: _SubscriptableSpecialForm = ... +Callable: _SubscriptableSpecialForm = ... +Type: _SubscriptableSpecialForm = ... NoReturn: _SpecialForm = ... -Optional: _SpecialForm -Tuple: _SpecialForm -ClassVar: _SpecialForm +Optional: _SubscriptableSpecialForm +Tuple: _SubscriptableSpecialForm +ClassVar: _SubscriptableSpecialForm if sys.version_info >= (3, 8): - Final: _SpecialForm + Final: _SubscriptableSpecialForm def final(f: _T) -> _T: ... - Literal: _SpecialForm + Literal: _SubscriptableSpecialForm # TypedDict is a (non-subscriptable) special form. TypedDict: object if sys.version_info >= (3, 11): - Self: _SpecialForm + Self: _SubscriptableSpecialForm Never: _SpecialForm = ... if sys.version_info < (3, 7):