Skip to content

Commit f6503fd

Browse files
authored
Drop Python 3.8 support in typing[_extensions] and types (#13763)
1 parent 0a3d8d2 commit f6503fd

File tree

4 files changed

+78
-113
lines changed

4 files changed

+78
-113
lines changed

stdlib/@tests/test_cases/typing/check_all.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
"""
55
from __future__ import annotations
66

7-
import sys
87
from typing import *
98
from zipfile import *
109

11-
if sys.version_info >= (3, 9):
12-
x: Annotated[int, 42]
10+
x: Annotated[int, 42]
1311

1412
p: Path

stdlib/types.pyi

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ __all__ = [
4747
"WrapperDescriptorType",
4848
"resolve_bases",
4949
"CellType",
50+
"GenericAlias",
5051
]
5152

52-
if sys.version_info >= (3, 9):
53-
__all__ += ["GenericAlias"]
54-
5553
if sys.version_info >= (3, 10):
5654
__all__ += ["EllipsisType", "NoneType", "NotImplementedType", "UnionType"]
5755

@@ -320,11 +318,10 @@ class MappingProxyType(Mapping[_KT, _VT_co]):
320318
def get(self, key: _KT, /) -> _VT_co | None: ...
321319
@overload
322320
def get(self, key: _KT, default: _VT_co | _T2, /) -> _VT_co | _T2: ...
323-
if sys.version_info >= (3, 9):
324-
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
325-
def __reversed__(self) -> Iterator[_KT]: ...
326-
def __or__(self, value: Mapping[_T1, _T2], /) -> dict[_KT | _T1, _VT_co | _T2]: ...
327-
def __ror__(self, value: Mapping[_T1, _T2], /) -> dict[_KT | _T1, _VT_co | _T2]: ...
321+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
322+
def __reversed__(self) -> Iterator[_KT]: ...
323+
def __or__(self, value: Mapping[_T1, _T2], /) -> dict[_KT | _T1, _VT_co | _T2]: ...
324+
def __ror__(self, value: Mapping[_T1, _T2], /) -> dict[_KT | _T1, _VT_co | _T2]: ...
328325

329326
class SimpleNamespace:
330327
__hash__: ClassVar[None] # type: ignore[assignment]
@@ -425,8 +422,7 @@ class AsyncGeneratorType(AsyncGenerator[_YieldT_co, _SendT_contra]):
425422
@overload
426423
async def athrow(self, typ: BaseException, val: None = None, tb: TracebackType | None = ..., /) -> _YieldT_co: ...
427424
def aclose(self) -> Coroutine[Any, Any, None]: ...
428-
if sys.version_info >= (3, 9):
429-
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
425+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
430426

431427
@final
432428
class CoroutineType(Coroutine[_YieldT_co, _SendT_contra, _ReturnT_co]):
@@ -647,30 +643,29 @@ def coroutine(func: Callable[_P, Generator[Any, Any, _R]]) -> Callable[_P, Await
647643
@overload
648644
def coroutine(func: _Fn) -> _Fn: ...
649645

650-
if sys.version_info >= (3, 9):
651-
class GenericAlias:
652-
@property
653-
def __origin__(self) -> type | TypeAliasType: ...
646+
class GenericAlias:
647+
@property
648+
def __origin__(self) -> type | TypeAliasType: ...
649+
@property
650+
def __args__(self) -> tuple[Any, ...]: ...
651+
@property
652+
def __parameters__(self) -> tuple[Any, ...]: ...
653+
def __new__(cls, origin: type, args: Any, /) -> Self: ...
654+
def __getitem__(self, typeargs: Any, /) -> GenericAlias: ...
655+
def __eq__(self, value: object, /) -> bool: ...
656+
def __hash__(self) -> int: ...
657+
def __mro_entries__(self, bases: Iterable[object], /) -> tuple[type, ...]: ...
658+
if sys.version_info >= (3, 11):
654659
@property
655-
def __args__(self) -> tuple[Any, ...]: ...
660+
def __unpacked__(self) -> bool: ...
656661
@property
657-
def __parameters__(self) -> tuple[Any, ...]: ...
658-
def __new__(cls, origin: type, args: Any, /) -> Self: ...
659-
def __getitem__(self, typeargs: Any, /) -> GenericAlias: ...
660-
def __eq__(self, value: object, /) -> bool: ...
661-
def __hash__(self) -> int: ...
662-
def __mro_entries__(self, bases: Iterable[object], /) -> tuple[type, ...]: ...
663-
if sys.version_info >= (3, 11):
664-
@property
665-
def __unpacked__(self) -> bool: ...
666-
@property
667-
def __typing_unpacked_tuple_args__(self) -> tuple[Any, ...] | None: ...
668-
if sys.version_info >= (3, 10):
669-
def __or__(self, value: Any, /) -> UnionType: ...
670-
def __ror__(self, value: Any, /) -> UnionType: ...
671-
672-
# GenericAlias delegates attr access to `__origin__`
673-
def __getattr__(self, name: str) -> Any: ...
662+
def __typing_unpacked_tuple_args__(self) -> tuple[Any, ...] | None: ...
663+
if sys.version_info >= (3, 10):
664+
def __or__(self, value: Any, /) -> UnionType: ...
665+
def __ror__(self, value: Any, /) -> UnionType: ...
666+
667+
# GenericAlias delegates attr access to `__origin__`
668+
def __getattr__(self, name: str) -> Any: ...
674669

675670
if sys.version_info >= (3, 10):
676671
@final

stdlib/typing.pyi

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ from types import (
1313
BuiltinFunctionType,
1414
CodeType,
1515
FunctionType,
16+
GenericAlias,
1617
MethodDescriptorType,
1718
MethodType,
1819
MethodWrapperType,
@@ -22,20 +23,20 @@ from types import (
2223
)
2324
from typing_extensions import Never as _Never, ParamSpec as _ParamSpec, deprecated
2425

25-
if sys.version_info >= (3, 9):
26-
from types import GenericAlias
2726
if sys.version_info >= (3, 10):
2827
from types import UnionType
2928

3029
__all__ = [
3130
"AbstractSet",
31+
"Annotated",
3232
"Any",
3333
"AnyStr",
3434
"AsyncContextManager",
3535
"AsyncGenerator",
3636
"AsyncIterable",
3737
"AsyncIterator",
3838
"Awaitable",
39+
"BinaryIO",
3940
"ByteString",
4041
"Callable",
4142
"ChainMap",
@@ -49,10 +50,12 @@ __all__ = [
4950
"Deque",
5051
"Dict",
5152
"Final",
53+
"ForwardRef",
5254
"FrozenSet",
5355
"Generator",
5456
"Generic",
5557
"Hashable",
58+
"IO",
5659
"ItemsView",
5760
"Iterable",
5861
"Iterator",
@@ -61,12 +64,16 @@ __all__ = [
6164
"Literal",
6265
"Mapping",
6366
"MappingView",
67+
"Match",
6468
"MutableMapping",
6569
"MutableSequence",
6670
"MutableSet",
6771
"NamedTuple",
6872
"NewType",
73+
"NoReturn",
6974
"Optional",
75+
"OrderedDict",
76+
"Pattern",
7077
"Protocol",
7178
"Reversible",
7279
"Sequence",
@@ -80,6 +87,7 @@ __all__ = [
8087
"SupportsInt",
8188
"SupportsRound",
8289
"Text",
90+
"TextIO",
8391
"Tuple",
8492
"Type",
8593
"TypeVar",
@@ -96,14 +104,8 @@ __all__ = [
96104
"no_type_check_decorator",
97105
"overload",
98106
"runtime_checkable",
99-
"ForwardRef",
100-
"NoReturn",
101-
"OrderedDict",
102107
]
103108

104-
if sys.version_info >= (3, 9):
105-
__all__ += ["Annotated", "BinaryIO", "IO", "Match", "Pattern", "TextIO"]
106-
107109
if sys.version_info >= (3, 10):
108110
__all__ += ["Concatenate", "ParamSpec", "ParamSpecArgs", "ParamSpecKwargs", "TypeAlias", "TypeGuard", "is_typeddict"]
109111

@@ -203,7 +205,6 @@ class _SpecialForm(_Final):
203205

204206
Union: _SpecialForm
205207
Generic: _SpecialForm
206-
# Protocol is only present in 3.8 and later, but mypy needs it unconditionally
207208
Protocol: _SpecialForm
208209
Callable: _SpecialForm
209210
Type: _SpecialForm
@@ -386,8 +387,7 @@ ChainMap = _Alias()
386387

387388
OrderedDict = _Alias()
388389

389-
if sys.version_info >= (3, 9):
390-
Annotated: _SpecialForm
390+
Annotated: _SpecialForm
391391

392392
# Predefined type variables.
393393
AnyStr = TypeVar("AnyStr", str, bytes) # noqa: Y001
@@ -858,19 +858,12 @@ _get_type_hints_obj_allowed_types: typing_extensions.TypeAlias = ( # noqa: Y042
858858
| MethodDescriptorType
859859
)
860860

861-
if sys.version_info >= (3, 9):
862-
def get_type_hints(
863-
obj: _get_type_hints_obj_allowed_types,
864-
globalns: dict[str, Any] | None = None,
865-
localns: Mapping[str, Any] | None = None,
866-
include_extras: bool = False,
867-
) -> dict[str, Any]: ...
868-
869-
else:
870-
def get_type_hints(
871-
obj: _get_type_hints_obj_allowed_types, globalns: dict[str, Any] | None = None, localns: Mapping[str, Any] | None = None
872-
) -> dict[str, Any]: ...
873-
861+
def get_type_hints(
862+
obj: _get_type_hints_obj_allowed_types,
863+
globalns: dict[str, Any] | None = None,
864+
localns: Mapping[str, Any] | None = None,
865+
include_extras: bool = False,
866+
) -> dict[str, Any]: ...
874867
def get_args(tp: Any) -> tuple[Any, ...]: ...
875868

876869
if sys.version_info >= (3, 10):
@@ -879,15 +872,10 @@ if sys.version_info >= (3, 10):
879872
@overload
880873
def get_origin(tp: UnionType) -> type[UnionType]: ...
881874

882-
if sys.version_info >= (3, 9):
883-
@overload
884-
def get_origin(tp: GenericAlias) -> type: ...
885-
@overload
886-
def get_origin(tp: Any) -> Any | None: ...
887-
888-
else:
889-
def get_origin(tp: Any) -> Any | None: ...
890-
875+
@overload
876+
def get_origin(tp: GenericAlias) -> type: ...
877+
@overload
878+
def get_origin(tp: Any) -> Any | None: ...
891879
@overload
892880
def cast(typ: type[_T], val: Any) -> _T: ...
893881
@overload
@@ -914,8 +902,6 @@ if sys.version_info >= (3, 11):
914902
# Type constructors
915903

916904
class NamedTuple(tuple[Any, ...]):
917-
if sys.version_info < (3, 9):
918-
_field_types: ClassVar[dict[str, type]]
919905
_field_defaults: ClassVar[dict[str, Any]]
920906
_fields: ClassVar[tuple[str, ...]]
921907
# __orig_bases__ sometimes exists on <3.12, but not consistently
@@ -942,9 +928,8 @@ class NamedTuple(tuple[Any, ...]):
942928
@type_check_only
943929
class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
944930
__total__: ClassVar[bool]
945-
if sys.version_info >= (3, 9):
946-
__required_keys__: ClassVar[frozenset[str]]
947-
__optional_keys__: ClassVar[frozenset[str]]
931+
__required_keys__: ClassVar[frozenset[str]]
932+
__optional_keys__: ClassVar[frozenset[str]]
948933
# __orig_bases__ sometimes exists on <3.12, but not consistently,
949934
# so we only add it to the stub on 3.12+
950935
if sys.version_info >= (3, 12):
@@ -964,17 +949,16 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
964949
def items(self) -> dict_items[str, object]: ...
965950
def keys(self) -> dict_keys[str, object]: ...
966951
def values(self) -> dict_values[str, object]: ...
967-
if sys.version_info >= (3, 9):
968-
@overload
969-
def __or__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ...
970-
@overload
971-
def __or__(self, value: dict[str, Any], /) -> dict[str, object]: ...
972-
@overload
973-
def __ror__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ...
974-
@overload
975-
def __ror__(self, value: dict[str, Any], /) -> dict[str, object]: ...
976-
# supposedly incompatible definitions of __or__ and __ior__
977-
def __ior__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ... # type: ignore[misc]
952+
@overload
953+
def __or__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ...
954+
@overload
955+
def __or__(self, value: dict[str, Any], /) -> dict[str, object]: ...
956+
@overload
957+
def __ror__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ...
958+
@overload
959+
def __ror__(self, value: dict[str, Any], /) -> dict[str, object]: ...
960+
# supposedly incompatible definitions of __or__ and __ior__
961+
def __ior__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ... # type: ignore[misc]
978962

979963
@final
980964
class ForwardRef(_Final):
@@ -985,11 +969,8 @@ class ForwardRef(_Final):
985969
__forward_is_argument__: bool
986970
__forward_is_class__: bool
987971
__forward_module__: Any | None
988-
if sys.version_info >= (3, 9):
989-
# The module and is_class arguments were added in later Python 3.9 versions.
990-
def __init__(self, arg: str, is_argument: bool = True, module: Any | None = None, *, is_class: bool = False) -> None: ...
991-
else:
992-
def __init__(self, arg: str, is_argument: bool = True) -> None: ...
972+
973+
def __init__(self, arg: str, is_argument: bool = True, module: Any | None = None, *, is_class: bool = False) -> None: ...
993974

994975
if sys.version_info >= (3, 13):
995976
@overload
@@ -1019,12 +1000,10 @@ class ForwardRef(_Final):
10191000
*,
10201001
recursive_guard: frozenset[str],
10211002
) -> Any | None: ...
1022-
elif sys.version_info >= (3, 9):
1003+
else:
10231004
def _evaluate(
10241005
self, globalns: dict[str, Any] | None, localns: Mapping[str, Any] | None, recursive_guard: frozenset[str]
10251006
) -> Any | None: ...
1026-
else:
1027-
def _evaluate(self, globalns: dict[str, Any] | None, localns: Mapping[str, Any] | None) -> Any | None: ...
10281007

10291008
def __eq__(self, other: object) -> bool: ...
10301009
def __hash__(self) -> int: ...

stdlib/typing_extensions.pyi

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import typing
55
from _collections_abc import dict_items, dict_keys, dict_values
66
from _typeshed import IdentityFunction, Incomplete, Unused
77
from contextlib import AbstractAsyncContextManager as AsyncContextManager, AbstractContextManager as ContextManager
8-
from types import ModuleType
8+
from types import GenericAlias, ModuleType
99
from typing import ( # noqa: Y022,Y037,Y038,Y039
1010
IO as IO,
1111
TYPE_CHECKING as TYPE_CHECKING,
@@ -67,8 +67,6 @@ from typing import ( # noqa: Y022,Y037,Y038,Y039
6767

6868
if sys.version_info >= (3, 10):
6969
from types import UnionType
70-
if sys.version_info >= (3, 9):
71-
from types import GenericAlias
7270

7371
# Please keep order the same as at runtime.
7472
__all__ = [
@@ -254,18 +252,17 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
254252
def keys(self) -> dict_keys[str, object]: ...
255253
def values(self) -> dict_values[str, object]: ...
256254
def __delitem__(self, k: Never) -> None: ...
257-
if sys.version_info >= (3, 9):
258-
@overload
259-
def __or__(self, value: Self, /) -> Self: ...
260-
@overload
261-
def __or__(self, value: dict[str, Any], /) -> dict[str, object]: ...
262-
@overload
263-
def __ror__(self, value: Self, /) -> Self: ...
264-
@overload
265-
def __ror__(self, value: dict[str, Any], /) -> dict[str, object]: ...
266-
# supposedly incompatible definitions of `__ior__` and `__or__`:
267-
# Since this module defines "Self" it is not recognized by Ruff as typing_extensions.Self
268-
def __ior__(self, value: Self, /) -> Self: ... # type: ignore[misc]
255+
@overload
256+
def __or__(self, value: Self, /) -> Self: ...
257+
@overload
258+
def __or__(self, value: dict[str, Any], /) -> dict[str, object]: ...
259+
@overload
260+
def __ror__(self, value: Self, /) -> Self: ...
261+
@overload
262+
def __ror__(self, value: dict[str, Any], /) -> dict[str, object]: ...
263+
# supposedly incompatible definitions of `__ior__` and `__or__`:
264+
# Since this module defines "Self" it is not recognized by Ruff as typing_extensions.Self
265+
def __ior__(self, value: Self, /) -> Self: ... # type: ignore[misc]
269266

270267
OrderedDict = _Alias()
271268

@@ -281,10 +278,8 @@ if sys.version_info >= (3, 10):
281278
@overload
282279
def get_origin(tp: UnionType) -> type[UnionType]: ...
283280

284-
if sys.version_info >= (3, 9):
285-
@overload
286-
def get_origin(tp: GenericAlias) -> type: ...
287-
281+
@overload
282+
def get_origin(tp: GenericAlias) -> type: ...
288283
@overload
289284
def get_origin(tp: ParamSpecArgs | ParamSpecKwargs) -> ParamSpec: ...
290285
@overload
@@ -364,8 +359,6 @@ else:
364359
) -> IdentityFunction: ...
365360

366361
class NamedTuple(tuple[Any, ...]):
367-
if sys.version_info < (3, 9):
368-
_field_types: ClassVar[dict[str, type]]
369362
_field_defaults: ClassVar[dict[str, Any]]
370363
_fields: ClassVar[tuple[str, ...]]
371364
__orig_bases__: ClassVar[tuple[Any, ...]]

0 commit comments

Comments
 (0)