8000 Update typing_extensions to 4.13.0rc1 · srittau/typeshed@cf0f99f · GitHub
[go: up one dir, main page]

Skip to content

Commit cf0f99f

Browse files
committed
Update typing_extensions to 4.13.0rc1
Also sort __all__ to match the implementation Closes: python#13670
1 parent 45e9a79 commit cf0f99f

File tree

3 files changed

+105
-45
lines changed

3 files changed

+105
-45
lines changed

stdlib/@tests/stubtest_allowlists/common.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,13 @@ 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+
# Initialized at runtime
505+
typing_extensions\.TypeAliasType\.__parameters__
506+
typing_extensions\.TypeAliasType\.__value__
507+
508+
# Typing-related weirdness
509+
typing._SpecialForm.__call__
510+
typing._SpecialForm.__init__
506511

507512
# These are abstract properties at runtime,
508513
# but marking them as such in the stub breaks half the the typed-Python ecosystem (see #8726)

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[Any] | 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: 94 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
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,70 @@ 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+
def __parameters__(self) -> tuple[TypeVar | ParamSpec, ...]: ...
580+
@property
581+
def __name__(self) -> str: ...
582+
# It's writable on types, but not on instances of TypeAliasType.
583+
@property
584+
def __module__(self) -> str | None: ... # type: ignore[override]
585+
# Returns typing._GenericAlias, which isn't stubbed.
586+
def __getitem__(self, parameters: Incomplete | tuple[Incomplete, ...]) -> Any: ...
587+
def __init_subclass__(cls, *args, **kwargs) -> NoReturn: ...
588+
def __call__(self) -> NoReturn: ...
589+
if sys.version_info >= (3, 10):
590+
def __or__(self, right: Any) -> _SpecialForm: ...
591+
def __ror__(self, left: Any) -> _SpecialForm: ...
592+
593+
# PEP 727
572594
class Doc:
573595
documentation: str
574596
def __init__(self, documentation: str, /) -> None: ...
575597
def __hash__(self) -> int: ...
576598
def __eq__(self, other: object) -> bool: ...
599+
600+
# PEP 728
601+
class _NoExtraItemsType: ...
602+
603+
NoExtraItems: _NoExtraItemsType
604+
605+
# PEP 747
606+
TypeForm: _SpecialForm
607+
608+
class Format(enum.IntEnum):
609+
VALUE = 1
610+
FORWARDREF = 2 1241
611+
STRING = 3
612+
613+
# PEP 649/749
614+
def get_annotations(
615+
obj: Callable[..., object] | type[Any] | ModuleType, # any callable, class, or module
616+
*,
617+
globals: Mapping[str, Any] | None = None, # value types depend on the key
618+
locals: Mapping[str, Any] | None = None, # value types depend on the key
619+
eval_str: bool = False,
620+
format: Format = Format.VALUE,
621+
) -> dict[str, Any]: ... # values are type expressions
622+
def evaluate_forward_ref(
623+
forward_ref: ForwardRef,
624+
*,
625+
owner: Callable[..., object] | type[Any] | ModuleType | None = None, # any callable, class, or module
626+
globals: Mapping[str, Any] | None = None, # value types depend on the key
627+
locals: Mapping[str, Any] | None = None, # value types depend on the key
628+
type_params: Iterable[TypeVar | ParamSpec | TypeVarTuple] | None = None,
629+
format: Format = Format.VALUE,
630+
_recursive_guard: Container[str] = ...,
631+
) -> Any: ... # str if format is Format.STRING, otherwise a type expression

0 commit comments

Comments
 (0)
0