Skip to content

Commit 5a8f8aa

Browse files
authored
Update typing_extensions to 4.13.0rc1 (#13671)
Also sort __all__ to match the implementation
1 parent 45e9a79 commit 5a8f8aa

File tree

9 files changed

+115
-55
lines changed

9 files changed

+115
-55
lines changed

requirements-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ stubdefaulter==0.1.0
1818
termcolor>=2.3
1919
tomli==2.2.1
2020
tomlkit==0.13.2
21-
typing_extensions>=4.12.0rc1
21+
typing_extensions>=4.13.0rc1
2222
uv==0.5.14
2323

2424
# Utilities for typeshed infrastructure scripts.

stdlib/@tests/stubtest_allowlists/common.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,9 @@ typing(_extensions)?\.ValuesView
501501
typing_extensions\.Final
502502
typing_extensions\.LiteralString
503503

504-
typing._SpecialForm.__call__ # Typing-related weirdness
505-
typing._SpecialForm.__init__ # Typing-related weirdness
504+
# Typing-related weirdness
505+
typing._SpecialForm.__call__
506+
typing._SpecialForm.__init__
506507

507508
# These are abstract properties at runtime,
508509
# but marking them as such in the stub breaks half the the typed-Python ecosystem (see #8726)
@@ -525,6 +526,10 @@ typing(_extensions)?\.(Async)?ContextManager
525526
typing(_extensions)?\.IO\.__iter__
526527
typing(_extensions)?\.IO\.__next__
527528

529+
# Will always raise. Not included to avoid type checkers inferring that
530+
# TypeAliasType instances are callable.
531+
typing_extensions.TypeAliasType.__call__
532+
528533
types.MethodType.__closure__ # read-only but not actually a property; stubtest thinks it doesn't exist.
529534
types.MethodType.__code__ # read-only but not actually a property; stubtest thinks it doesn't exist.
530535
types.MethodType.__defaults__ # read-only but not actually a property; stubtest thinks it doesn't exist.

stdlib/@tests/stubtest_allowlists/py310.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ poplib.POP3_SSL.stls # bad declaration of inherited function. See poplib.pyi
240240
tkinter.test # Modules that exist at runtime, but shouldn't be added to typeshed
241241
tkinter\.test\..+ # Modules that exist at runtime, but shouldn't be added to typeshed
242242

243-
# Exist at runtime for internal reasons, no need to put them in the stub
244-
typing_extensions\.TypeAliasType\.__call__
245-
typing_extensions\.TypeAliasType\.__init_subclass__
246243
# We call them read-only properties, runtime implementation is slightly different
247244
typing_extensions\.TypeAliasType\.__(parameters|type_params|name|module|value)__
248245

stdlib/@tests/stubtest_allowlists/py311.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,6 @@ poplib.POP3_SSL.stls # bad declaration of inherited function. See poplib.pyi
204204
tkinter.test # Modules that exist at runtime, but shouldn't be added to typeshed
205205
tkinter\.test\..+ # Modules that exist at runtime, but shouldn't be added to typeshed
206206

207-
# Exist at runtime for internal reasons, no need to put them in the stub
208-
typing_extensions\.TypeAliasType\.__call__
209-
typing_extensions\.TypeAliasType\.__init_subclass__
210207
# We call them read-only properties, runtime implementation is slightly different
211208
typing_extensions\.TypeAliasType\.__(parameters|type_params|name|module|value)__
212209

stdlib/@tests/stubtest_allowlists/py312.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
zoneinfo.ZoneInfo.from_file # Pos-only parameters had different "names" in different Python versions
1111

12+
# Initialized at runtime
13+
typing_extensions.TypeAliasType.__parameters__
14+
typing_extensions.TypeAliasType.__value__
15+
1216

1317
# ====================================
1418
# Pre-existing errors from Python 3.11

stdlib/@tests/stubtest_allowlists/py313.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
zoneinfo.ZoneInfo.from_file # Pos-only parameters had different "names" in different Python versions
1616

17+
# Initialized at runtime
18+
typing_extensions.TypeAliasType.__parameters__
19+
typing_extensions.TypeAliasType.__value__
20+
1721

1822
# =======
1923
# >= 3.11

stdlib/@tests/stubtest_allowlists/py39.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,6 @@ poplib.POP3_SSL.stls # bad declaration of inherited function. See poplib.pyi
213213
tkinter.test # Modules that exist at runtime, but shouldn't be added to typeshed
214214
tkinter\.test\..+ # Modules that exist at runtime, but shouldn't be added to typeshed
215215

216-
# Exist at runtime for internal reasons, no need to put them in the stub
217-
typing_extensions\.TypeAliasType\.__call__
218-
typing_extensions\.TypeAliasType\.__init_subclass__
219216
# We call them read-only properties, runtime implementation is slightly different
220217
typing_extensions\.TypeAliasType\.__(parameters|type_params|name|module|value)__
221218

stdlib/inspect.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,12 @@ class Signature:
345345

346346
if sys.version_info >= (3, 10):
347347
def get_annotations(
348-
obj: Callable[..., object] | type[Any] | ModuleType,
348+
obj: Callable[..., object] | type[object] | ModuleType, # any callable, class, or module
349349
*,
350-
globals: Mapping[str, Any] | None = None,
351-
locals: Mapping[str, Any] | None = None,
350+
globals: Mapping[str, Any] | None = None, # value types depend on the key
351+
locals: Mapping[str, Any] | None = None, # value types depend on the key
352352
eval_str: bool = False,
353-
) -> dict[str, Any]: ...
353+
) -> dict[str, Any]: ... # values are type expressions
354354

355355
# The name is the same as the enum's name in CPython
356356
class _ParameterKind(enum.IntEnum):

stdlib/typing_extensions.pyi

Lines changed: 95 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import abc
2+
import enum
23
import sys
34
import typing
45
from _collections_abc import dict_items, dict_keys, dict_values
5-
from _typeshed import IdentityFunction
6+
from _typeshed import IdentityFunction, Incomplete, Unused
67
from contextlib import AbstractAsyncContextManager as AsyncContextManager, AbstractContextManager as ContextManager
8+
from types import ModuleType
79
from typing import ( # noqa: Y022,Y037,Y038,Y039
810
IO as IO,
911
TYPE_CHECKING as TYPE_CHECKING,
@@ -68,9 +70,10 @@ if sys.version_info >= (3, 10):
6870
if sys.version_info >= (3, 9):
6971
from types import GenericAlias
7072

73+
# Please keep order the same as at runtime.
7174
__all__ = [
75+
# Super-special typing primitives.
7276
"Any",
73-
"Buffer",
7477
"ClassVar",
7578
"Concatenate",
7679
"Final",
@@ -83,35 +86,51 @@ __all__ = [
8386
"TypeVar",
8487
"TypeVarTuple",
8588
"Unpack",
89+
# ABCs (from collections.abc).
8690
"Awaitable",
8791
"AsyncIterator",
8892
"AsyncIterable",
8993
"Coroutine",
9094
"AsyncGenerator",
9195
"AsyncContextManager",
92-
"CapsuleType",
96+
"Buffer",
9397
"ChainMap",
98+
# Concrete collection types.
9499
"ContextManager",
95100
"Counter",
96101
"Deque",
97102
"DefaultDict",
98103
"NamedTuple",
99104
"OrderedDict",
100105
"TypedDict",
101-
"SupportsIndex",
106+
# Structural checks, a.k.a. protocols.
102107
"SupportsAbs",
103-
"SupportsRound",
104108
"SupportsBytes",
105109
"SupportsComplex",
106110
"SupportsFloat",
111+
"SupportsIndex",
107112
"SupportsInt",
113+
"SupportsRound",
114+
# One-off things.
108115
"Annotated",
109116
"assert_never",
110117
"assert_type",
118+
"clear_overloads",
111119
"dataclass_transform",
112120
"deprecated",
121+
"Doc",
122+
"evaluate_forward_ref",
123+
"get_overloads",
113124
"final",
125+
"Format",
126+
"get_annotations",
127+
"get_args",
128+
"get_origin",
129+
"get_original_bases",
130+
"get_protocol_members",
131+
"get_type_hints",
114132
"IntVar",
133+
"is_protocol",
115134
"is_typeddict",
116135
"Literal",
117136
"NewType",
@@ -124,26 +143,25 @@ __all__ = [
124143
"Text",
125144
"TypeAlias",
126145
"TypeAliasType",
146+
"TypeForm",
127147
"TypeGuard",
148+
"TypeIs",
128149
"TYPE_CHECKING",
129150
"Never",
130151
"NoReturn",
152+
"ReadOnly",
131153
"Required",
132154
"NotRequired",
133-
"clear_overloads",
134-
"get_args",
135-
"get_origin",
136-
"get_original_bases",
137-
"get_overloads",
138-
"get_type_hints",
155+
"NoDefault",
156+
"NoExtraItems",
157+
# Pure aliases, have always been in typing
139158
"AbstractSet",
140159
"AnyStr",
141160
"BinaryIO",
142161
"Callable",
143162
"Collection",
144163
"Container",
145164
"Dict",
146-
"Doc",
147165
"ForwardRef",
148166
"FrozenSet",
149167
"Generator",
@@ -161,7 +179,6 @@ __all__ = [
161179
"MutableMapping",
162180
"MutableSequence",
163181
"MutableSet",
164-
"NoDefault",
165182
"Optional",
166183
"Pattern",
167184
"Reversible",
@@ -173,12 +190,10 @@ __all__ = [
173190
"Union",
174191
"ValuesView",
175192
"cast",
176-
"get_protocol_members",
177-
"is_protocol",
178193
"no_type_check",
179194
"no_type_check_decorator",
180-
"ReadOnly",
181-
"TypeIs",
195+
# Added dynamically
196+
"CapsuleType",
182197
]
183198

184199
_T = typing.TypeVar("_T")
@@ -382,33 +397,11 @@ if sys.version_info >= (3, 12):
382397
SupportsIndex as SupportsIndex,
383398
SupportsInt as SupportsInt,
384399
SupportsRound as SupportsRound,
385-
TypeAliasType as TypeAliasType,
386400
override as override,
387401
)
388402
else:
389403
def override(arg: _F, /) -> _F: ...
390404
def get_original_bases(cls: type, /) -> tuple[Any, ...]: ...
391-
@final
392-
class TypeAliasType:
393-
def __init__(
394-
self, name: str, value: Any, *, type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] = ()
395-
) -> None: ...
396-
@property
397-
def __value__(self) -> Any: ...
398-
@property
399-
def __type_params__(self) -> tuple[TypeVar | ParamSpec | TypeVarTuple, ...]: ...
400-
@property
401-
def __parameters__(self) -> tuple[Any, ...]: ...
402-
@property
403-
def __name__(self) -> str: ...
404-
# It's writable on types, but not on instances of TypeAliasType.
405-
@property
406-
def __module__(self) -> str | None: ... # type: ignore[override]
407-
# Returns typing._GenericAlias, which isn't stubbed.
408-
def __getitem__(self, parameters: Any) -> Any: ...
409-
if sys.version_info >= (3, 10):
410-
def __or__(self, right: Any) -> _SpecialForm: ...
411-
def __ror__(self, left: Any) -> _SpecialForm: ...
412405

413406
# mypy and pyright object to this being both ABC and Protocol.
414407
# At runtime it inherits from ABC and is not a Protocol, but it is on the
@@ -569,8 +562,71 @@ else:
569562
ReadOnly: _SpecialForm
570563
TypeIs: _SpecialForm
571564

565+
# TypeAliasType was added in Python 3.12, but had significant changes in 3.14.
566+
if sys.version_info >= (3, 14):
567+
from typing import TypeAliasType as TypeAliasType
568+
else:
569+
@final
570+
class TypeAliasType:
571+
def __init__(
572+
self, name: str, value: Any, *, type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] = ()
573+
) -> None: ... # value is a type expression
574+
@property
575+
def __value__(self) -> Any: ... # a type expression
576+
@property
577+
def __type_params__(self) -> tuple[TypeVar | ParamSpec | TypeVarTuple, ...]: ...
578+
@property
579+
# `__parameters__` can include special forms if a `TypeVarTuple` was
580+
# passed as a `type_params` element to the constructor method.
581+
def __parameters__(self) -> tuple[TypeVar | ParamSpec | Any, ...]: ...
582+
@property
583+
def __name__(self) -> str: ...
584+
# It's writable on types, but not on instances of TypeAliasType.
585+
@property
586+
def __module__(self) -> str | None: ... # type: ignore[override]
587+
# Returns typing._GenericAlias, which isn't stubbed.
588+
def __getitem__(self, parameters: Incomplete | tuple[Incomplete, ...]) -> Any: ...
589+
def __init_subclass__(cls, *args: Unused, **kwargs: Unused) -> NoReturn: ...
590+
if sys.version_info >= (3, 10):
591+
def __or__(self, right: Any) -> _SpecialForm: ...
592+
def __ror__(self, left: Any) -> _SpecialForm: ...
593+
594+
# PEP 727
572595
class Doc:
573596
documentation: str
574597
def __init__(self, documentation: str, /) -> None: ...
575598
def __hash__(self) -> int: ...
576599
def __eq__(self, other: object) -> bool: ...
600+
601+
# PEP 728
602+
class _NoExtraItemsType: ...
603+
604+
NoExtraItems: _NoExtraItemsType
605+
606+
# PEP 747
607+
TypeForm: _SpecialForm
608+
609+
class Format(enum.IntEnum):
610+
VALUE = 1
611+
FORWARDREF = 2
612+
STRING = 3
613+
614+
# PEP 649/749
615+
def get_annotations(
616+
obj: Callable[..., object] | type[object] | ModuleType, # any callable, class, or module
617+
*,
618+
globals: Mapping[str, Any] | None = None, # value types depend on the key
619+
locals: Mapping[str, Any] | None = None, # value types depend on the key
620+
eval_str: bool = False,
621+
format: Format = Format.VALUE, # noqa: Y011
622+
) -> dict[str, Any]: ... # values are type expressions
623+
def evaluate_forward_ref(
624+
forward_ref: ForwardRef,
625+
*,
626+
owner: Callable[..., object] | type[object] | ModuleType | None = None, # any callable, class, or module
627+
globals: Mapping[str, Any] | None = None, # value types depend on the key
628+
locals: Mapping[str, Any] | None = None, # value types depend on the key
629+
type_params: Iterable[TypeVar | ParamSpec | TypeVarTuple] | None = None,
630+
format: Format = Format.VALUE, # noqa: Y011
631+
_recursive_guard: Container[str] = ...,
632+
) -> Any: ... # str if format is Format.STRING, otherwise a type expression

0 commit comments

Comments
 (0)