Drop Python 3.8 support in typing[_extensions] and types (#13763)

This commit is contained in:
Joren Hammudoglu
2025-04-02 08:56:56 +02:00
committed by GitHub
parent 0a3d8d2696
commit f6503fd9ab
4 changed files with 77 additions and 112 deletions
+36 -57
View File
@@ -13,6 +13,7 @@ from types import (
BuiltinFunctionType,
CodeType,
FunctionType,
GenericAlias,
MethodDescriptorType,
MethodType,
MethodWrapperType,
@@ -22,13 +23,12 @@ from types import (
)
from typing_extensions import Never as _Never, ParamSpec as _ParamSpec, deprecated
if sys.version_info >= (3, 9):
from types import GenericAlias
if sys.version_info >= (3, 10):
from types import UnionType
__all__ = [
"AbstractSet",
"Annotated",
"Any",
"AnyStr",
"AsyncContextManager",
@@ -36,6 +36,7 @@ __all__ = [
"AsyncIterable",
"AsyncIterator",
"Awaitable",
"BinaryIO",
"ByteString",
"Callable",
"ChainMap",
@@ -49,10 +50,12 @@ __all__ = [
"Deque",
"Dict",
"Final",
"ForwardRef",
"FrozenSet",
"Generator",
"Generic",
"Hashable",
"IO",
"ItemsView",
"Iterable",
"Iterator",
@@ -61,12 +64,16 @@ __all__ = [
"Literal",
"Mapping",
"MappingView",
"Match",
"MutableMapping",
"MutableSequence",
"MutableSet",
"NamedTuple",
"NewType",
"NoReturn",
"Optional",
"OrderedDict",
"Pattern",
"Protocol",
"Reversible",
"Sequence",
@@ -80,6 +87,7 @@ __all__ = [
"SupportsInt",
"SupportsRound",
"Text",
"TextIO",
"Tuple",
"Type",
"TypeVar",
@@ -96,14 +104,8 @@ __all__ = [
"no_type_check_decorator",
"overload",
"runtime_checkable",
"ForwardRef",
"NoReturn",
"OrderedDict",
]
if sys.version_info >= (3, 9):
__all__ += ["Annotated", "BinaryIO", "IO", "Match", "Pattern", "TextIO"]
if sys.version_info >= (3, 10):
__all__ += ["Concatenate", "ParamSpec", "ParamSpecArgs", "ParamSpecKwargs", "TypeAlias", "TypeGuard", "is_typeddict"]
@@ -203,7 +205,6 @@ class _SpecialForm(_Final):
Union: _SpecialForm
Generic: _SpecialForm
# Protocol is only present in 3.8 and later, but mypy needs it unconditionally
Protocol: _SpecialForm
Callable: _SpecialForm
Type: _SpecialForm
@@ -386,8 +387,7 @@ ChainMap = _Alias()
OrderedDict = _Alias()
if sys.version_info >= (3, 9):
Annotated: _SpecialForm
Annotated: _SpecialForm
# Predefined type variables.
AnyStr = TypeVar("AnyStr", str, bytes) # noqa: Y001
@@ -858,19 +858,12 @@ _get_type_hints_obj_allowed_types: typing_extensions.TypeAlias = ( # noqa: Y042
| MethodDescriptorType
)
if sys.version_info >= (3, 9):
def get_type_hints(
obj: _get_type_hints_obj_allowed_types,
globalns: dict[str, Any] | None = None,
localns: Mapping[str, Any] | None = None,
include_extras: bool = False,
) -> dict[str, Any]: ...
else:
def get_type_hints(
obj: _get_type_hints_obj_allowed_types, globalns: dict[str, Any] | None = None, localns: Mapping[str, Any] | None = None
) -> dict[str, Any]: ...
def get_type_hints(
obj: _get_type_hints_obj_allowed_types,
globalns: dict[str, Any] | None = None,
localns: Mapping[str, Any] | None = None,
include_extras: bool = False,
) -> dict[str, Any]: ...
def get_args(tp: Any) -> tuple[Any, ...]: ...
if sys.version_info >= (3, 10):
@@ -879,15 +872,10 @@ if sys.version_info >= (3, 10):
@overload
def get_origin(tp: UnionType) -> type[UnionType]: ...
if sys.version_info >= (3, 9):
@overload
def get_origin(tp: GenericAlias) -> type: ...
@overload
def get_origin(tp: Any) -> Any | None: ...
else:
def get_origin(tp: Any) -> Any | None: ...
@overload
def get_origin(tp: GenericAlias) -> type: ...
@overload
def get_origin(tp: Any) -> Any | None: ...
@overload
def cast(typ: type[_T], val: Any) -> _T: ...
@overload
@@ -914,8 +902,6 @@ if sys.version_info >= (3, 11):
# Type constructors
class NamedTuple(tuple[Any, ...]):
if sys.version_info < (3, 9):
_field_types: ClassVar[dict[str, type]]
_field_defaults: ClassVar[dict[str, Any]]
_fields: ClassVar[tuple[str, ...]]
# __orig_bases__ sometimes exists on <3.12, but not consistently
@@ -942,9 +928,8 @@ class NamedTuple(tuple[Any, ...]):
@type_check_only
class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
__total__: ClassVar[bool]
if sys.version_info >= (3, 9):
__required_keys__: ClassVar[frozenset[str]]
__optional_keys__: ClassVar[frozenset[str]]
__required_keys__: ClassVar[frozenset[str]]
__optional_keys__: ClassVar[frozenset[str]]
# __orig_bases__ sometimes exists on <3.12, but not consistently,
# so we only add it to the stub on 3.12+
if sys.version_info >= (3, 12):
@@ -964,17 +949,16 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
def items(self) -> dict_items[str, object]: ...
def keys(self) -> dict_keys[str, object]: ...
def values(self) -> dict_values[str, object]: ...
if sys.version_info >= (3, 9):
@overload
def __or__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ...
@overload
def __or__(self, value: dict[str, Any], /) -> dict[str, object]: ...
@overload
def __ror__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ...
@overload
def __ror__(self, value: dict[str, Any], /) -> dict[str, object]: ...
# supposedly incompatible definitions of __or__ and __ior__
def __ior__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ... # type: ignore[misc]
@overload
def __or__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ...
@overload
def __or__(self, value: dict[str, Any], /) -> dict[str, object]: ...
@overload
def __ror__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ...
@overload
def __ror__(self, value: dict[str, Any], /) -> dict[str, object]: ...
# supposedly incompatible definitions of __or__ and __ior__
def __ior__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ... # type: ignore[misc]
@final
class ForwardRef(_Final):
@@ -985,11 +969,8 @@ class ForwardRef(_Final):
__forward_is_argument__: bool
__forward_is_class__: bool
__forward_module__: Any | None
if sys.version_info >= (3, 9):
# The module and is_class arguments were added in later Python 3.9 versions.
def __init__(self, arg: str, is_argument: bool = True, module: Any | None = None, *, is_class: bool = False) -> None: ...
else:
def __init__(self, arg: str, is_argument: bool = True) -> None: ...
def __init__(self, arg: str, is_argument: bool = True, module: Any | None = None, *, is_class: bool = False) -> None: ...
if sys.version_info >= (3, 13):
@overload
@@ -1019,12 +1000,10 @@ class ForwardRef(_Final):
*,
recursive_guard: frozenset[str],
) -> Any | None: ...
elif sys.version_info >= (3, 9):
else:
def _evaluate(
self, globalns: dict[str, Any] | None, localns: Mapping[str, Any] | None, recursive_guard: frozenset[str]
) -> Any | None: ...
else:
def _evaluate(self, globalns: dict[str, Any] | None, localns: Mapping[str, Any] | None) -> Any | None: ...
def __eq__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...