From cf0f99fef8bed4058ec8fe6dee928fbcd3271e22 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 19 Mar 2025 12:58:00 +0100 Subject: [PATCH 01/13] Update typing_extensions to 4.13.0rc1 Also sort __all__ to match the implementation Closes: #13670 --- stdlib/@tests/stubtest_allowlists/common.txt | 9 +- stdlib/inspect.pyi | 8 +- stdlib/typing_extensions.pyi | 133 +++++++++++++------ 3 files changed, 105 insertions(+), 45 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index f3cb0b2b52e7..6025562d2cf8 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -501,8 +501,13 @@ typing(_extensions)?\.ValuesView typing_extensions\.Final typing_extensions\.LiteralString -typing._SpecialForm.__call__ # Typing-related weirdness -typing._SpecialForm.__init__ # Typing-related weirdness +# Initialized at runtime +typing_extensions\.TypeAliasType\.__parameters__ +typing_extensions\.TypeAliasType\.__value__ + +# Typing-related weirdness +typing._SpecialForm.__call__ +typing._SpecialForm.__init__ # These are abstract properties at runtime, # but marking them as such in the stub breaks half the the typed-Python ecosystem (see #8726) diff --git a/stdlib/inspect.pyi b/stdlib/inspect.pyi index 229eb2135690..42043781cdf3 100644 --- a/stdlib/inspect.pyi +++ b/stdlib/inspect.pyi @@ -345,12 +345,12 @@ class Signature: if sys.version_info >= (3, 10): def get_annotations( - obj: Callable[..., object] | type[Any] | ModuleType, + obj: Callable[..., object] | type[Any] | ModuleType, # any callable, class, or module *, - globals: Mapping[str, Any] | None = None, - locals: Mapping[str, Any] | None = None, + globals: Mapping[str, Any] | None = None, # value types depend on the key + locals: Mapping[str, Any] | None = None, # value types depend on the key eval_str: bool = False, - ) -> dict[str, Any]: ... + ) -> dict[str, Any]: ... # values are type expressions # The name is the same as the enum's name in CPython class _ParameterKind(enum.IntEnum): diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index fd98722b10a8..8628b0906139 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -1,9 +1,11 @@ import abc +import enum import sys import typing from _collections_abc import dict_items, dict_keys, dict_values -from _typeshed import IdentityFunction +from _typeshed import IdentityFunction, Incomplete from contextlib import AbstractAsyncContextManager as AsyncContextManager, AbstractContextManager as ContextManager +from types import ModuleType from typing import ( # noqa: Y022,Y037,Y038,Y039 IO as IO, TYPE_CHECKING as TYPE_CHECKING, @@ -68,9 +70,10 @@ if sys.version_info >= (3, 10): if sys.version_info >= (3, 9): from types import GenericAlias +# Please keep order the same as at runtime. __all__ = [ + # Super-special typing primitives. "Any", - "Buffer", "ClassVar", "Concatenate", "Final", @@ -83,14 +86,16 @@ __all__ = [ "TypeVar", "TypeVarTuple", "Unpack", + # ABCs (from collections.abc). "Awaitable", "AsyncIterator", "AsyncIterable", "Coroutine", "AsyncGenerator", "AsyncContextManager", - "CapsuleType", + "Buffer", "ChainMap", + # Concrete collection types. "ContextManager", "Counter", "Deque", @@ -98,20 +103,34 @@ __all__ = [ "NamedTuple", "OrderedDict", "TypedDict", - "SupportsIndex", + # Structural checks, a.k.a. protocols. "SupportsAbs", - "SupportsRound", "SupportsBytes", "SupportsComplex", "SupportsFloat", + "SupportsIndex", "SupportsInt", + "SupportsRound", + # One-off things. "Annotated", "assert_never", "assert_type", + "clear_overloads", "dataclass_transform", "deprecated", + "Doc", + "evaluate_forward_ref", + "get_overloads", "final", + "Format", + "get_annotations", + "get_args", + "get_origin", + "get_original_bases", + "get_protocol_members", + "get_type_hints", "IntVar", + "is_protocol", "is_typeddict", "Literal", "NewType", @@ -124,18 +143,18 @@ __all__ = [ "Text", "TypeAlias", "TypeAliasType", + "TypeForm", "TypeGuard", + "TypeIs", "TYPE_CHECKING", "Never", "NoReturn", + "ReadOnly", "Required", "NotRequired", - "clear_overloads", - "get_args", - "get_origin", - "get_original_bases", - "get_overloads", - "get_type_hints", + "NoDefault", + "NoExtraItems", + # Pure aliases, have always been in typing "AbstractSet", "AnyStr", "BinaryIO", @@ -143,7 +162,6 @@ __all__ = [ "Collection", "Container", "Dict", - "Doc", "ForwardRef", "FrozenSet", "Generator", @@ -161,7 +179,6 @@ __all__ = [ "MutableMapping", "MutableSequence", "MutableSet", - "NoDefault", "Optional", "Pattern", "Reversible", @@ -173,12 +190,10 @@ __all__ = [ "Union", "ValuesView", "cast", - "get_protocol_members", - "is_protocol", "no_type_check", "no_type_check_decorator", - "ReadOnly", - "TypeIs", + # Added dynamically + "CapsuleType", ] _T = typing.TypeVar("_T") @@ -382,33 +397,11 @@ if sys.version_info >= (3, 12): SupportsIndex as SupportsIndex, SupportsInt as SupportsInt, SupportsRound as SupportsRound, - TypeAliasType as TypeAliasType, override as override, ) else: def override(arg: _F, /) -> _F: ... def get_original_bases(cls: type, /) -> tuple[Any, ...]: ... - @final - class TypeAliasType: - def __init__( - self, name: str, value: Any, *, type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] = () - ) -> None: ... - @property - def __value__(self) -> Any: ... - @property - def __type_params__(self) -> tuple[TypeVar | ParamSpec | TypeVarTuple, ...]: ... - @property - def __parameters__(self) -> tuple[Any, ...]: ... - @property - def __name__(self) -> str: ... - # It's writable on types, but not on instances of TypeAliasType. - @property - def __module__(self) -> str | None: ... # type: ignore[override] - # Returns typing._GenericAlias, which isn't stubbed. - def __getitem__(self, parameters: Any) -> Any: ... - if sys.version_info >= (3, 10): - def __or__(self, right: Any) -> _SpecialForm: ... - def __ror__(self, left: Any) -> _SpecialForm: ... # mypy and pyright object to this being both ABC and Protocol. # At runtime it inherits from ABC and is not a Protocol, but it is on the @@ -569,8 +562,70 @@ else: ReadOnly: _SpecialForm TypeIs: _SpecialForm +# TypeAliasType was added in Python 3.12, but had significant changes in 3.14. +if sys.version_info >= (3, 14): + from typing import TypeAliasType as TypeAliasType +else: + @final + class TypeAliasType: + def __init__( + self, name: str, value: Any, *, type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] = () + ) -> None: ... # value is a type expression + @property + def __value__(self) -> Any: ... # a type expression + @property + def __type_params__(self) -> tuple[TypeVar | ParamSpec | TypeVarTuple, ...]: ... + @property + def __parameters__(self) -> tuple[TypeVar | ParamSpec, ...]: ... + @property + def __name__(self) -> str: ... + # It's writable on types, but not on instances of TypeAliasType. + @property + def __module__(self) -> str | None: ... # type: ignore[override] + # Returns typing._GenericAlias, which isn't stubbed. + def __getitem__(self, parameters: Incomplete | tuple[Incomplete, ...]) -> Any: ... + def __init_subclass__(cls, *args, **kwargs) -> NoReturn: ... + def __call__(self) -> NoReturn: ... + if sys.version_info >= (3, 10): + def __or__(self, right: Any) -> _SpecialForm: ... + def __ror__(self, left: Any) -> _SpecialForm: ... + +# PEP 727 class Doc: documentation: str def __init__(self, documentation: str, /) -> None: ... def __hash__(self) -> int: ... def __eq__(self, other: object) -> bool: ... + +# PEP 728 +class _NoExtraItemsType: ... + +NoExtraItems: _NoExtraItemsType + +# PEP 747 +TypeForm: _SpecialForm + +class Format(enum.IntEnum): + VALUE = 1 + FORWARDREF = 2 + STRING = 3 + +# PEP 649/749 +def get_annotations( + obj: Callable[..., object] | type[Any] | ModuleType, # any callable, class, or module + *, + globals: Mapping[str, Any] | None = None, # value types depend on the key + locals: Mapping[str, Any] | None = None, # value types depend on the key + eval_str: bool = False, + format: Format = Format.VALUE, +) -> dict[str, Any]: ... # values are type expressions +def evaluate_forward_ref( + forward_ref: ForwardRef, + *, + owner: Callable[..., object] | type[Any] | ModuleType | None = None, # any callable, class, or module + globals: Mapping[str, Any] | None = None, # value types depend on the key + locals: Mapping[str, Any] | None = None, # value types depend on the key + type_params: Iterable[TypeVar | ParamSpec | TypeVarTuple] | None = None, + format: Format = Format.VALUE, + _recursive_guard: Container[str] = ..., +) -> Any: ... # str if format is Format.STRING, otherwise a type expression From 125ed8ada88e613a816a2aa491674e8c78ed88d8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Mar 2025 12:00:27 +0000 Subject: [PATCH 02/13] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/inspect.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/inspect.pyi b/stdlib/inspect.pyi index 42043781cdf3..c1e6355ede2c 100644 --- a/stdlib/inspect.pyi +++ b/stdlib/inspect.pyi @@ -345,7 +345,7 @@ class Signature: if sys.version_info >= (3, 10): def get_annotations( - obj: Callable[..., object] | type[Any] | ModuleType, # any callable, class, or module + obj: Callable[..., object] | type[Any] | ModuleType, # any callable, class, or module *, globals: Mapping[str, Any] | None = None, # value types depend on the key locals: Mapping[str, Any] | None = None, # value types depend on the key From 1ee04d6ef252881c55e7f53e0686015d9990bfb4 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 19 Mar 2025 13:00:46 +0100 Subject: [PATCH 03/13] Reorder allowlist --- stdlib/@tests/stubtest_allowlists/common.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index 6025562d2cf8..e8623b6d7d2b 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -501,10 +501,6 @@ typing(_extensions)?\.ValuesView typing_extensions\.Final typing_extensions\.LiteralString -# Initialized at runtime -typing_extensions\.TypeAliasType\.__parameters__ -typing_extensions\.TypeAliasType\.__value__ - # Typing-related weirdness typing._SpecialForm.__call__ typing._SpecialForm.__init__ @@ -530,6 +526,10 @@ typing(_extensions)?\.(Async)?ContextManager typing(_extensions)?\.IO\.__iter__ typing(_extensions)?\.IO\.__next__ +# Initialized at runtime +typing_extensions.TypeAliasType.__parameters__ +typing_extensions.TypeAliasType.__value__ + types.MethodType.__closure__ # read-only but not actually a property; stubtest thinks it doesn't exist. types.MethodType.__code__ # read-only but not actually a property; stubtest thinks it doesn't exist. types.MethodType.__defaults__ # read-only but not actually a property; stubtest thinks it doesn't exist. From 206224740edfefd452c7517a4390ee4822345ea8 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 19 Mar 2025 13:04:39 +0100 Subject: [PATCH 04/13] Update typing_extensions version in requirements --- requirements-tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 0f7faa5dbf4a..61165b749a1f 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -18,7 +18,7 @@ stubdefaulter==0.1.0 termcolor>=2.3 tomli==2.2.1 tomlkit==0.13.2 -typing_extensions>=4.12.0rc1 +typing_extensions>=4.13.0rc1 uv==0.5.14 # Utilities for typeshed infrastructure scripts. From d2783597b58773d7d4b82fc7f94382ecf7924773 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 19 Mar 2025 13:07:15 +0100 Subject: [PATCH 05/13] Move allowlist entries to 3.12/3.13(?) --- stdlib/@tests/stubtest_allowlists/common.txt | 4 ---- stdlib/@tests/stubtest_allowlists/py312.txt | 4 ++++ stdlib/@tests/stubtest_allowlists/py313.txt | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index e8623b6d7d2b..f0df8a2ad6a8 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -526,10 +526,6 @@ typing(_extensions)?\.(Async)?ContextManager typing(_extensions)?\.IO\.__iter__ typing(_extensions)?\.IO\.__next__ -# Initialized at runtime -typing_extensions.TypeAliasType.__parameters__ -typing_extensions.TypeAliasType.__value__ - types.MethodType.__closure__ # read-only but not actually a property; stubtest thinks it doesn't exist. types.MethodType.__code__ # read-only but not actually a property; stubtest thinks it doesn't exist. types.MethodType.__defaults__ # read-only but not actually a property; stubtest thinks it doesn't exist. diff --git a/stdlib/@tests/stubtest_allowlists/py312.txt b/stdlib/@tests/stubtest_allowlists/py312.txt index 51f169f91088..aaea7009760b 100644 --- a/stdlib/@tests/stubtest_allowlists/py312.txt +++ b/stdlib/@tests/stubtest_allowlists/py312.txt @@ -9,6 +9,10 @@ zoneinfo.ZoneInfo.from_file # Pos-only parameters had different "names" in different Python versions +# Initialized at runtime +typing_extensions.TypeAliasType.__parameters__ +typing_extensions.TypeAliasType.__value__ + # ==================================== # Pre-existing errors from Python 3.11 diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index 86faeafc4f65..ba44606f9179 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -14,6 +14,10 @@ zoneinfo.ZoneInfo.from_file # Pos-only parameters had different "names" in different Python versions +# Initialized at runtime +typing_extensions.TypeAliasType.__parameters__ +typing_extensions.TypeAliasType.__value__ + # ======= # >= 3.11 From 845802f46c6bcc288556279b4aec97677f049ede Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 19 Mar 2025 13:07:58 +0100 Subject: [PATCH 06/13] Add missing annotations --- stdlib/typing_extensions.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 8628b0906139..03aeccd154c3 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -3,7 +3,7 @@ import enum import sys import typing from _collections_abc import dict_items, dict_keys, dict_values -from _typeshed import IdentityFunction, Incomplete +from _typeshed import IdentityFunction, Incomplete, Unused from contextlib import AbstractAsyncContextManager as AsyncContextManager, AbstractContextManager as ContextManager from types import ModuleType from typing import ( # noqa: Y022,Y037,Y038,Y039 @@ -584,7 +584,7 @@ else: def __module__(self) -> str | None: ... # type: ignore[override] # Returns typing._GenericAlias, which isn't stubbed. def __getitem__(self, parameters: Incomplete | tuple[Incomplete, ...]) -> Any: ... - def __init_subclass__(cls, *args, **kwargs) -> NoReturn: ... + def __init_subclass__(cls, *args: Unused, **kwargs: Unused) -> NoReturn: ... def __call__(self) -> NoReturn: ... if sys.version_info >= (3, 10): def __or__(self, right: Any) -> _SpecialForm: ... From df8abca522fc3689ef5eb5aa36fd0dbba71faf94 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 19 Mar 2025 13:10:22 +0100 Subject: [PATCH 07/13] Remove unnecessary allowlist entries --- stdlib/@tests/stubtest_allowlists/py310.txt | 3 --- stdlib/@tests/stubtest_allowlists/py311.txt | 3 --- stdlib/@tests/stubtest_allowlists/py39.txt | 3 --- 3 files changed, 9 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py310.txt b/stdlib/@tests/stubtest_allowlists/py310.txt index aa3af5ccc4b8..9f6ce2cf82e6 100644 --- a/stdlib/@tests/stubtest_allowlists/py310.txt +++ b/stdlib/@tests/stubtest_allowlists/py310.txt @@ -240,9 +240,6 @@ poplib.POP3_SSL.stls # bad declaration of inherited function. See poplib.pyi tkinter.test # Modules that exist at runtime, but shouldn't be added to typeshed tkinter\.test\..+ # Modules that exist at runtime, but shouldn't be added to typeshed -# Exist at runtime for internal reasons, no need to put them in the stub -typing_extensions\.TypeAliasType\.__call__ -typing_extensions\.TypeAliasType\.__init_subclass__ # We call them read-only properties, runtime implementation is slightly different typing_extensions\.TypeAliasType\.__(parameters|type_params|name|module|value)__ diff --git a/stdlib/@tests/stubtest_allowlists/py311.txt b/stdlib/@tests/stubtest_allowlists/py311.txt index 07c67b0584bb..2b7e1b3e527c 100644 --- a/stdlib/@tests/stubtest_allowlists/py311.txt +++ b/stdlib/@tests/stubtest_allowlists/py311.txt @@ -204,9 +204,6 @@ poplib.POP3_SSL.stls # bad declaration of inherited function. See poplib.pyi tkinter.test # Modules that exist at runtime, but shouldn't be added to typeshed tkinter\.test\..+ # Modules that exist at runtime, but shouldn't be added to typeshed -# Exist at runtime for internal reasons, no need to put them in the stub -typing_extensions\.TypeAliasType\.__call__ -typing_extensions\.TypeAliasType\.__init_subclass__ # We call them read-only properties, runtime implementation is slightly different typing_extensions\.TypeAliasType\.__(parameters|type_params|name|module|value)__ diff --git a/stdlib/@tests/stubtest_allowlists/py39.txt b/stdlib/@tests/stubtest_allowlists/py39.txt index f35239fff80b..b52ad6594b78 100644 --- a/stdlib/@tests/stubtest_allowlists/py39.txt +++ b/stdlib/@tests/stubtest_allowlists/py39.txt @@ -213,9 +213,6 @@ poplib.POP3_SSL.stls # bad declaration of inherited function. See poplib.pyi tkinter.test # Modules that exist at runtime, but shouldn't be added to typeshed tkinter\.test\..+ # Modules that exist at runtime, but shouldn't be added to typeshed -# Exist at runtime for internal reasons, no need to put them in the stub -typing_extensions\.TypeAliasType\.__call__ -typing_extensions\.TypeAliasType\.__init_subclass__ # We call them read-only properties, runtime implementation is slightly different typing_extensions\.TypeAliasType\.__(parameters|type_params|name|module|value)__ From 63bddaa08b7deb632d419db7d291111fe71a5bf0 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 19 Mar 2025 13:14:58 +0100 Subject: [PATCH 08/13] Ignore flake8 warnings --- stdlib/typing_extensions.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 03aeccd154c3..01a24fde5b93 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -617,7 +617,7 @@ def get_annotations( globals: Mapping[str, Any] | None = None, # value types depend on the key locals: Mapping[str, Any] | None = None, # value types depend on the key eval_str: bool = False, - format: Format = Format.VALUE, + format: Format = Format.VALUE, # noqa: Y011 ) -> dict[str, Any]: ... # values are type expressions def evaluate_forward_ref( forward_ref: ForwardRef, @@ -626,6 +626,6 @@ def evaluate_forward_ref( globals: Mapping[str, Any] | None = None, # value types depend on the key locals: Mapping[str, Any] | None = None, # value types depend on the key type_params: Iterable[TypeVar | ParamSpec | TypeVarTuple] | None = None, - format: Format = Format.VALUE, + format: Format = Format.VALUE, # noqa: Y011 _recursive_guard: Container[str] = ..., ) -> Any: ... # str if format is Format.STRING, otherwise a type expression From 60c3bc57ab115c5fd8bbfbb6ddd135b1e29b5f94 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 19 Mar 2025 13:24:15 +0100 Subject: [PATCH 09/13] Use `type[object]` --- stdlib/inspect.pyi | 2 +- stdlib/typing_extensions.pyi | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/inspect.pyi b/stdlib/inspect.pyi index c1e6355ede2c..5bebe9bf4482 100644 --- a/stdlib/inspect.pyi +++ b/stdlib/inspect.pyi @@ -345,7 +345,7 @@ class Signature: if sys.version_info >= (3, 10): def get_annotations( - obj: Callable[..., object] | type[Any] | ModuleType, # any callable, class, or module + obj: Callable[..., object] | type[object] | ModuleType, # any callable, class, or module *, globals: Mapping[str, Any] | None = None, # value types depend on the key locals: Mapping[str, Any] | None = None, # value types depend on the key diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 01a24fde5b93..5d43c9f2b020 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -612,7 +612,7 @@ class Format(enum.IntEnum): # PEP 649/749 def get_annotations( - obj: Callable[..., object] | type[Any] | ModuleType, # any callable, class, or module + obj: Callable[..., object] | type[object] | ModuleType, # any callable, class, or module *, globals: Mapping[str, Any] | None = None, # value types depend on the key locals: Mapping[str, Any] | None = None, # value types depend on the key @@ -622,7 +622,7 @@ def get_annotations( def evaluate_forward_ref( forward_ref: ForwardRef, *, - owner: Callable[..., object] | type[Any] | ModuleType | None = None, # any callable, class, or module + owner: Callable[..., object] | type[object] | ModuleType | None = None, # any callable, class, or module globals: Mapping[str, Any] | None = None, # value types depend on the key locals: Mapping[str, Any] | None = None, # value types depend on the key type_params: Iterable[TypeVar | ParamSpec | TypeVarTuple] | None = None, From a1715b199096a9024791328079f1818b4738105b Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 19 Mar 2025 13:25:38 +0100 Subject: [PATCH 10/13] Remove TypeAliasType.__call__ --- stdlib/@tests/stubtest_allowlists/common.txt | 4 ++++ stdlib/typing_extensions.pyi | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index f0df8a2ad6a8..a74701e50e2a 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -526,6 +526,10 @@ typing(_extensions)?\.(Async)?ContextManager typing(_extensions)?\.IO\.__iter__ typing(_extensions)?\.IO\.__next__ +# Will always raise. Not included to avoid type checkers inferring that +# TypeAliasType instances are callable. +typing_extensions.TypeAliasType.__call__ + types.MethodType.__closure__ # read-only but not actually a property; stubtest thinks it doesn't exist. types.MethodType.__code__ # read-only but not actually a property; stubtest thinks it doesn't exist. types.MethodType.__defaults__ # read-only but not actually a property; stubtest thinks it doesn't exist. diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 5d43c9f2b020..87e6a4a425b1 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -585,7 +585,6 @@ else: # Returns typing._GenericAlias, which isn't stubbed. def __getitem__(self, parameters: Incomplete | tuple[Incomplete, ...]) -> Any: ... def __init_subclass__(cls, *args: Unused, **kwargs: Unused) -> NoReturn: ... - def __call__(self) -> NoReturn: ... if sys.version_info >= (3, 10): def __or__(self, right: Any) -> _SpecialForm: ... def __ror__(self, left: Any) -> _SpecialForm: ... From 9b89e3c163a514251c73788d0907698408535f9b Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 19 Mar 2025 13:33:40 +0100 Subject: [PATCH 11/13] TypeAliasType.__parameters__ can include special forms --- stdlib/typing_extensions.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 87e6a4a425b1..5b6af6ddbdc1 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -576,7 +576,7 @@ else: @property def __type_params__(self) -> tuple[TypeVar | ParamSpec | TypeVarTuple, ...]: ... @property - def __parameters__(self) -> tuple[TypeVar | ParamSpec, ...]: ... + def __parameters__(self) -> tuple[TypeVar | ParamSpec | Any, ...]: ... # can include special forms @property def __name__(self) -> str: ... # It's writable on types, but not on instances of TypeAliasType. From 1b4a83af85b91913274bb178649c23c85cab3f1d Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 19 Mar 2025 13:38:59 +0100 Subject: [PATCH 12/13] Update a comment Co-authored-by: Alex Waygood --- stdlib/typing_extensions.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 5b6af6ddbdc1..973cfd6d4427 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -576,7 +576,8 @@ else: @property def __type_params__(self) -> tuple[TypeVar | ParamSpec | TypeVarTuple, ...]: ... @property - def __parameters__(self) -> tuple[TypeVar | ParamSpec | Any, ...]: ... # can include special forms + # `__parameters__` can include special forms if a `TypeVarTuple` was passed as a `type_params` element to the constructor method + def __parameters__(self) -> tuple[TypeVar | ParamSpec | Any, ...]: ... @property def __name__(self) -> str: ... # It's writable on types, but not on instances of TypeAliasType. From 8fa5a1b727ff46dc76f459181e7d672c91f952a2 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 19 Mar 2025 13:42:50 +0100 Subject: [PATCH 13/13] Split line --- stdlib/typing_extensions.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 973cfd6d4427..3d369dcd63b2 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -576,7 +576,8 @@ else: @property def __type_params__(self) -> tuple[TypeVar | ParamSpec | TypeVarTuple, ...]: ... @property - # `__parameters__` can include special forms if a `TypeVarTuple` was passed as a `type_params` element to the constructor method + # `__parameters__` can include special forms if a `TypeVarTuple` was + # passed as a `type_params` element to the constructor method. def __parameters__(self) -> tuple[TypeVar | ParamSpec | Any, ...]: ... @property def __name__(self) -> str: ...