Skip to content

Commit a7912d5

Browse files
Add Python 3.15 typing updates (#15725)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 38143a2 commit a7912d5

4 files changed

Lines changed: 52 additions & 22 deletions

File tree

stdlib/@tests/stubtest_allowlists/py315.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# TODO: Allowlist entries that should be fixed
33
# ============================================
44

5-
_collections_abc.__all__
65
_frozen_importlib.BuiltinImporter.load_module
76
_frozen_importlib.FrozenImporter.load_module
87
_frozen_importlib_external.FileFinder.discover
@@ -131,7 +130,6 @@ codecs.strict_errors
131130
codecs.xmlcharrefreplace_errors
132131
collections.Counter.__ixor__
133132
collections.Counter.__xor__
134-
collections.abc.__all__
135133
concurrent.interpreters._crossinterp.UNBOUND_ERROR
136134
concurrent.interpreters._crossinterp.UNBOUND_REMOVE
137135
concurrent.interpreters._crossinterp.UnboundItem.singleton
@@ -381,25 +379,16 @@ types.UnionType.__qualname__
381379
types.__all__
382380
typing.LiteralString
383381
typing.NewType.__mro_entries__
384-
typing.NoExtraItems
385382
typing.ParamSpec.__mro_entries__
386383
typing.ParamSpecArgs.__mro_entries__
387384
typing.ParamSpecKwargs.__mro_entries__
388385
typing.SupportsAbs.__type_params__
389386
typing.SupportsRound.__type_params__
390-
typing.TypeAliasType.__qualname__
391-
typing.TypeForm
392387
typing.TypeVar.__mro_entries__
393-
typing.TypeVarTuple.__bound__
394-
typing.TypeVarTuple.__contravariant__
395-
typing.TypeVarTuple.__covariant__
396-
typing.TypeVarTuple.__infer_variance__
397388
typing.TypeVarTuple.__mro_entries__
398389
typing.Union
399390
typing._SpecialForm.__mro_entries__
400-
typing.__all__
401-
typing.disjoint_base
402-
typing.no_type_check_decorator
391+
typing_extensions.__all__
403392
typing_extensions.Protocol
404393
unicodedata.block
405394
unicodedata.extended_pictographic

stdlib/_collections_abc.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ __all__ = [
6060
"ValuesView",
6161
"Sequence",
6262
"MutableSequence",
63-
"ByteString",
6463
]
64+
if sys.version_info < (3, 15):
65+
__all__ += ["ByteString"]
6566
if sys.version_info >= (3, 12):
6667
__all__ += ["Buffer"]
6768

stdlib/typing.pyi

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ __all__ = [
3939
"AsyncIterator",
4040
"Awaitable",
4141
"BinaryIO",
42-
"ByteString",
4342
"Callable",
4443
"ChainMap",
4544
"ClassVar",
@@ -110,14 +109,19 @@ __all__ = [
110109
"get_type_hints",
111110
"is_typeddict",
112111
"no_type_check",
113-
"no_type_check_decorator",
114112
"overload",
115113
"runtime_checkable",
116114
]
117115

116+
if sys.version_info < (3, 15):
117+
__all__ += ["ByteString", "no_type_check_decorator"]
118+
118119
if sys.version_info >= (3, 14):
119120
__all__ += ["evaluate_forward_ref"]
120121

122+
if sys.version_info >= (3, 15):
123+
__all__ += ["NoExtraItems", "TypeForm", "disjoint_base"]
124+
121125
if sys.version_info >= (3, 11):
122126
__all__ += [
123127
"LiteralString",
@@ -258,11 +262,31 @@ if sys.version_info >= (3, 11):
258262
class TypeVarTuple:
259263
@property
260264
def __name__(self) -> str: ...
265+
if sys.version_info >= (3, 15):
266+
@property
267+
def __bound__(self) -> Any | None: ... # AnnotationForm
268+
@property
269+
def __covariant__(self) -> bool: ...
270+
@property
271+
def __contravariant__(self) -> bool: ...
272+
@property
273+
def __infer_variance__(self) -> bool: ...
261274
if sys.version_info >= (3, 13):
262275
@property
263276
def __default__(self) -> Any: ... # AnnotationForm
264277
def has_default(self) -> bool: ...
265-
if sys.version_info >= (3, 13):
278+
if sys.version_info >= (3, 15):
279+
def __new__(
280+
cls,
281+
name: str,
282+
*,
283+
bound: Any | None = None, # AnnotationForm
284+
covariant: bool = False,
285+
contravariant: bool = False,
286+
default: Any = ..., # AnnotationForm
287+
infer_variance: bool = False,
288+
) -> Self: ...
289+
elif sys.version_info >= (3, 13):
266290
def __new__(cls, name: str, *, default: Any = ...) -> Self: ... # AnnotationForm
267291
elif sys.version_info >= (3, 12):
268292
def __new__(cls, name: str) -> Self: ...
@@ -397,12 +421,16 @@ _TC = TypeVar("_TC", bound=type[object])
397421
def overload(func: _F) -> _F: ...
398422
def no_type_check(arg: _F) -> _F: ...
399423

400-
if sys.version_info >= (3, 13):
401-
@deprecated("Deprecated since Python 3.13; removed in Python 3.15.")
402-
def no_type_check_decorator(decorator: Callable[_P, _T]) -> Callable[_P, _T]: ...
424+
if sys.version_info < (3, 15):
425+
if sys.version_info >= (3, 13):
426+
@deprecated("Deprecated since Python 3.13; removed in Python 3.15.")
427+
def no_type_check_decorator(decorator: Callable[_P, _T]) -> Callable[_P, _T]: ...
403428

404-
else:
405-
def no_type_check_decorator(decorator: Callable[_P, _T]) -> Callable[_P, _T]: ...
429+
else:
430+
def no_type_check_decorator(decorator: Callable[_P, _T]) -> Callable[_P, _T]: ...
431+
432+
if sys.version_info >= (3, 15):
433+
def disjoint_base(cls: _TC) -> _TC: ...
406434

407435
# This itself is only available during type checking
408436
def type_check_only(func_or_cls: _FT) -> _FT: ...
@@ -426,6 +454,13 @@ ChainMap = _Alias()
426454
OrderedDict = _Alias()
427455

428456
Annotated: _SpecialForm
457+
if sys.version_info >= (3, 15):
458+
@type_check_only
459+
class _NoExtraItemsType: ...
460+
461+
NoExtraItems: _NoExtraItemsType
462+
463+
TypeForm: _SpecialForm
429464

430465
# Predefined type variables.
431466
AnyStr = TypeVar("AnyStr", str, bytes) # noqa: Y001
@@ -1147,6 +1182,9 @@ if sys.version_info >= (3, 12):
11471182
def __parameters__(self) -> tuple[Any, ...]: ... # AnnotationForm
11481183
@property
11491184
def __name__(self) -> str: ...
1185+
if sys.version_info >= (3, 15):
1186+
@property
1187+
def __qualname__(self) -> str: ...
11501188
# It's writable on types, but not on instances of TypeAliasType.
11511189
@property
11521190
def __module__(self) -> str | None: ... # type: ignore[override]

stdlib/typing_extensions.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ from typing import ( # noqa: Y022,Y037,Y038,Y039,UP035
6868
cast as cast,
6969
is_typeddict as is_typeddict,
7070
no_type_check as no_type_check,
71-
no_type_check_decorator as no_type_check_decorator,
7271
overload as overload,
7372
type_check_only,
7473
)
@@ -210,6 +209,9 @@ _TC = _TypeVar("_TC", bound=type[object])
210209
_T_co = _TypeVar("_T_co", covariant=True) # Any type covariant containers.
211210
_T_contra = _TypeVar("_T_contra", contravariant=True)
212211

212+
if sys.version_info < (3, 15):
213+
def no_type_check_decorator(decorator: _F) -> _F: ...
214+
213215
# Do not import (and re-export) Protocol or runtime_checkable from
214216
# typing module because type checkers need to be able to distinguish
215217
# typing.Protocol and typing_extensions.Protocol so they can properly

0 commit comments

Comments
 (0)