diff --git a/stdlib/@python2/typing.pyi b/stdlib/@python2/typing.pyi index f0e3dc403..34f5d9d46 100644 --- a/stdlib/@python2/typing.pyi +++ b/stdlib/@python2/typing.pyi @@ -20,6 +20,7 @@ class TypeVar: _promote = object() +# N.B. Keep this definition in sync with typing_extensions._SpecialForm class _SpecialForm(object): def __getitem__(self, typeargs: Any) -> object: ... @@ -44,7 +45,7 @@ _F = TypeVar("_F", bound=Callable[..., Any]) def final(f: _F) -> _F: ... def overload(f: _F) -> _F: ... -Literal: _SpecialForm = ... +Literal: _SpecialForm # TypedDict is a (non-subscriptable) special form. TypedDict: object diff --git a/stdlib/@python2/typing_extensions.pyi b/stdlib/@python2/typing_extensions.pyi index 42d513501..539579105 100644 --- a/stdlib/@python2/typing_extensions.pyi +++ b/stdlib/@python2/typing_extensions.pyi @@ -27,8 +27,9 @@ from typing import ( # noqa Y022 _T = TypeVar("_T") _F = TypeVar("_F", bound=Callable[..., Any]) +# unfortunately we have to duplicate this class definition from typing.pyi or we break pytype class _SpecialForm: - def __getitem__(self, typeargs: Any) -> Any: ... + def __getitem__(self, typeargs: Any) -> object: ... # This alias for above is kept here for backwards compatibility. runtime = runtime_checkable diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 87abf763f..0513a2f53 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -29,6 +29,7 @@ class TypeVar: # Used for an undocumented mypy feature. Does not exist at runtime. _promote = object() +# N.B. Keep this definition in sync with typing_extensions._SpecialForm class _SpecialForm: def __getitem__(self, typeargs: Any) -> object: ... if sys.version_info >= (3, 10): @@ -138,13 +139,9 @@ if sys.version_info >= (3, 9): # Predefined type variables. AnyStr = TypeVar("AnyStr", str, bytes) # noqa: Y001 -if sys.version_info >= (3, 8): - # This class did actually exist in 3.7, but had a different base. - # We'll just pretend it didn't exist though: the main external use case for _ProtocolMeta is - # to inherit from for your own custom protocol metaclasses. If you're using 3.7, at runtime - # you'd use typing_extensions.Protocol, which would be unrelated to typing._ProtocolMeta and - # so you'd run into metaclass conflicts at runtime if you used typing._ProtocolMeta. - class _ProtocolMeta(ABCMeta): ... +# Technically in 3.7 this inherited from GenericMeta. But let's not reflect that, since +# type checkers tend to assume that Protocols all have the ABCMeta metaclass. +class _ProtocolMeta(ABCMeta): ... # Abstract base classes. diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index e4d4f055e..d1690e4e6 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -35,8 +35,12 @@ from typing import ( # noqa Y022 _T = TypeVar("_T") _F = TypeVar("_F", bound=Callable[..., Any]) +# unfortunately we have to duplicate this class definition from typing.pyi or we break pytype class _SpecialForm: - def __getitem__(self, typeargs: Any) -> Any: ... + def __getitem__(self, typeargs: Any) -> object: ... + if sys.version_info >= (3, 10): + def __or__(self, other: Any) -> _SpecialForm: ... + def __ror__(self, other: Any) -> _SpecialForm: ... # This alias for above is kept here for backwards compatibility. runtime = runtime_checkable @@ -51,11 +55,6 @@ Literal: _SpecialForm def IntVar(name: str) -> Any: ... # returns a new TypeVar -if sys.version_info < (3, 8): - # Technically in 3.6 this inherited from GenericMeta. But let's not reflect that, since - # type checkers tend to assume that Protocols all have the ABCMeta metaclass. - class _ProtocolMeta(abc.ABCMeta): ... - # Internal mypy fallback type for all typed dicts (does not exist at runtime) class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): __required_keys__: frozenset[str]