Skip to content

Update typing_extensions to 4.13.0rc1 #13671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 19, 2025
Merged
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,9 @@ typing(_extensions)?\.ValuesView
typing_extensions\.Final
typing_extensions\.LiteralString

typing._SpecialForm.__call__ # Typing-related weirdness
typing._SpecialForm.__init__ # Typing-related weirdness
# 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)
Expand All @@ -525,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.
Expand Down
3 changes: 0 additions & 3 deletions stdlib/@tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)__

Expand Down
3 changes: 0 additions & 3 deletions stdlib/@tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)__

Expand Down
4 changes: 4 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py313.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions stdlib/@tests/stubtest_allowlists/py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)__

Expand Down
8 changes: 4 additions & 4 deletions stdlib/inspect.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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[object] | 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):
Expand Down
134 changes: 95 additions & 39 deletions stdlib/typing_extensions.pyi
Original file line number Diff line number Diff line change
@@ -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, Unused
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,
Expand Down Expand Up @@ -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",
Expand All @@ -83,35 +86,51 @@ __all__ = [
"TypeVar",
"TypeVarTuple",
"Unpack",
# ABCs (from collections.abc).
"Awaitable",
"AsyncIterator",
"AsyncIterable",
"Coroutine",
"AsyncGenerator",
"AsyncContextManager",
"CapsuleType",
"Buffer",
"ChainMap",
# Concrete collection types.
"ContextManager",
"Counter",
"Deque",
"DefaultDict",
"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",
Expand All @@ -124,26 +143,25 @@ __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",
"Callable",
"Collection",
"Container",
"Dict",
"Doc",
"ForwardRef",
"FrozenSet",
"Generator",
Expand All @@ -161,7 +179,6 @@ __all__ = [
"MutableMapping",
"MutableSequence",
"MutableSet",
"NoDefault",
"Optional",
"Pattern",
"Reversible",
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -569,8 +562,71 @@ 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):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made an exception for our "next Python version" rule, as technically typing_extensions is not part of the stdlib.

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
# `__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.
@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: Unused, **kwargs: Unused) -> 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[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
eval_str: bool = False,
format: Format = Format.VALUE, # noqa: Y011
) -> dict[str, Any]: ... # values are type expressions
def evaluate_forward_ref(
forward_ref: ForwardRef,
*,
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,
format: Format = Format.VALUE, # noqa: Y011
_recursive_guard: Container[str] = ...,
) -> Any: ... # str if format is Format.STRING, otherwise a type expression
Loading