Use PEP 585 syntax wherever possible (#6717)

This commit is contained in:
Alex Waygood
2021-12-28 10:31:43 +00:00
committed by GitHub
parent e6cb341d94
commit 8d5d2520ac
237 changed files with 966 additions and 1069 deletions

View File

@@ -49,7 +49,6 @@ from typing import (
SupportsFloat,
SupportsInt,
SupportsRound,
Tuple,
Type,
TypeVar,
Union,
@@ -108,11 +107,11 @@ class object:
def __sizeof__(self) -> int: ...
# return type of pickle methods is rather hard to express in the current type system
# see #6661 and https://docs.python.org/3/library/pickle.html#object.__reduce__
def __reduce__(self) -> str | Tuple[Any, ...]: ...
def __reduce__(self) -> str | tuple[Any, ...]: ...
if sys.version_info >= (3, 8):
def __reduce_ex__(self, __protocol: SupportsIndex) -> str | Tuple[Any, ...]: ...
def __reduce_ex__(self, __protocol: SupportsIndex) -> str | tuple[Any, ...]: ...
else:
def __reduce_ex__(self, __protocol: int) -> str | Tuple[Any, ...]: ...
def __reduce_ex__(self, __protocol: int) -> str | tuple[Any, ...]: ...
def __dir__(self) -> Iterable[str]: ...
def __init_subclass__(cls) -> None: ...
@@ -141,14 +140,14 @@ class classmethod(Generic[_R]): # Special, only valid as a decorator.
class type(object):
__base__: type
__bases__: Tuple[type, ...]
__bases__: tuple[type, ...]
__basicsize__: int
__dict__: dict[str, Any]
__dictoffset__: int
__flags__: int
__itemsize__: int
__module__: str
__mro__: Tuple[type, ...]
__mro__: tuple[type, ...]
__name__: str
__qualname__: str
__text_signature__: str | None
@@ -156,11 +155,11 @@ class type(object):
@overload
def __init__(self, __o: object) -> None: ...
@overload
def __init__(self, __name: str, __bases: Tuple[type, ...], __dict: dict[str, Any], **kwds: Any) -> None: ...
def __init__(self, __name: str, __bases: tuple[type, ...], __dict: dict[str, Any], **kwds: Any) -> None: ...
@overload
def __new__(cls, __o: object) -> type: ...
@overload
def __new__(cls: Type[_TT], __name: str, __bases: Tuple[type, ...], __namespace: dict[str, Any], **kwds: Any) -> _TT: ...
def __new__(cls: Type[_TT], __name: str, __bases: tuple[type, ...], __namespace: dict[str, Any], **kwds: Any) -> _TT: ...
def __call__(self, *args: Any, **kwds: Any) -> Any: ...
def __subclasses__(self: _TT) -> list[_TT]: ...
# Note: the documentation doesn't specify what the return type is, the standard
@@ -169,7 +168,7 @@ class type(object):
def __instancecheck__(self, __instance: Any) -> bool: ...
def __subclasscheck__(self, __subclass: type) -> bool: ...
@classmethod
def __prepare__(metacls, __name: str, __bases: Tuple[type, ...], **kwds: Any) -> Mapping[str, object]: ...
def __prepare__(metacls, __name: str, __bases: tuple[type, ...], **kwds: Any) -> Mapping[str, object]: ...
if sys.version_info >= (3, 10):
def __or__(self, __t: Any) -> types.UnionType: ...
def __ror__(self, __t: Any) -> types.UnionType: ...
@@ -370,7 +369,7 @@ class str(Sequence[str]):
def count(self, x: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
def encode(self, encoding: str = ..., errors: str = ...) -> bytes: ...
def endswith(
self, __suffix: str | Tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
self, __suffix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> bool: ...
if sys.version_info >= (3, 8):
def expandtabs(self, tabsize: SupportsIndex = ...) -> str: ...
@@ -411,7 +410,7 @@ class str(Sequence[str]):
def split(self, sep: str | None = ..., maxsplit: SupportsIndex = ...) -> list[str]: ...
def splitlines(self, keepends: bool = ...) -> list[str]: ...
def startswith(
self, __prefix: str | Tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
self, __prefix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> bool: ...
def strip(self, __chars: str | None = ...) -> str: ...
def swapcase(self) -> str: ...
@@ -463,7 +462,7 @@ class bytes(ByteString):
) -> int: ...
def decode(self, encoding: str = ..., errors: str = ...) -> str: ...
def endswith(
self, __suffix: bytes | Tuple[bytes, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
self, __suffix: bytes | tuple[bytes, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> bool: ...
if sys.version_info >= (3, 8):
def expandtabs(self, tabsize: SupportsIndex = ...) -> bytes: ...
@@ -510,7 +509,7 @@ class bytes(ByteString):
def split(self, sep: bytes | None = ..., maxsplit: SupportsIndex = ...) -> list[bytes]: ...
def splitlines(self, keepends: bool = ...) -> list[bytes]: ...
def startswith(
self, __prefix: bytes | Tuple[bytes, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
self, __prefix: bytes | tuple[bytes, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> bool: ...
def strip(self, __bytes: bytes | None = ...) -> bytes: ...
def swapcase(self) -> bytes: ...
@@ -565,7 +564,7 @@ class bytearray(MutableSequence[int], ByteString):
def copy(self) -> bytearray: ...
def decode(self, encoding: str = ..., errors: str = ...) -> str: ...
def endswith(
self, __suffix: bytes | Tuple[bytes, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
self, __suffix: bytes | tuple[bytes, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> bool: ...
if sys.version_info >= (3, 8):
def expandtabs(self, tabsize: SupportsIndex = ...) -> bytearray: ...
@@ -614,7 +613,7 @@ class bytearray(MutableSequence[int], ByteString):
def split(self, sep: bytes | None = ..., maxsplit: SupportsIndex = ...) -> list[bytearray]: ...
def splitlines(self, keepends: bool = ...) -> list[bytearray]: ...
def startswith(
self, __prefix: bytes | Tuple[bytes, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
self, __prefix: bytes | tuple[bytes, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
) -> bool: ...
def strip(self, __bytes: bytes | None = ...) -> bytearray: ...
def swapcase(self) -> bytearray: ...
@@ -659,9 +658,9 @@ class bytearray(MutableSequence[int], ByteString):
class memoryview(Sized, Sequence[int]):
format: str
itemsize: int
shape: Tuple[int, ...] | None
strides: Tuple[int, ...] | None
suboffsets: Tuple[int, ...] | None
shape: tuple[int, ...] | None
strides: tuple[int, ...] | None
suboffsets: tuple[int, ...] | None
readonly: bool
ndim: int
@@ -675,7 +674,7 @@ class memoryview(Sized, Sequence[int]):
def __exit__(
self, __exc_type: Type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None
) -> None: ...
def cast(self, format: str, shape: list[int] | Tuple[int, ...] = ...) -> memoryview: ...
def cast(self, format: str, shape: list[int] | tuple[int, ...] = ...) -> memoryview: ...
@overload
def __getitem__(self, __i: SupportsIndex) -> int: ...
@overload
@@ -748,18 +747,18 @@ class tuple(Sequence[_T_co], Generic[_T_co]):
@overload
def __getitem__(self, __x: SupportsIndex) -> _T_co: ...
@overload
def __getitem__(self, __x: slice) -> Tuple[_T_co, ...]: ...
def __getitem__(self, __x: slice) -> tuple[_T_co, ...]: ...
def __iter__(self) -> Iterator[_T_co]: ...
def __lt__(self, __x: Tuple[_T_co, ...]) -> bool: ...
def __le__(self, __x: Tuple[_T_co, ...]) -> bool: ...
def __gt__(self, __x: Tuple[_T_co, ...]) -> bool: ...
def __ge__(self, __x: Tuple[_T_co, ...]) -> bool: ...
def __lt__(self, __x: tuple[_T_co, ...]) -> bool: ...
def __le__(self, __x: tuple[_T_co, ...]) -> bool: ...
def __gt__(self, __x: tuple[_T_co, ...]) -> bool: ...
def __ge__(self, __x: tuple[_T_co, ...]) -> bool: ...
@overload
def __add__(self, __x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ...
def __add__(self, __x: tuple[_T_co, ...]) -> tuple[_T_co, ...]: ...
@overload
def __add__(self, __x: Tuple[_T, ...]) -> Tuple[_T_co | _T, ...]: ...
def __mul__(self, __n: SupportsIndex) -> Tuple[_T_co, ...]: ...
def __rmul__(self, __n: SupportsIndex) -> Tuple[_T_co, ...]: ...
def __add__(self, __x: tuple[_T, ...]) -> tuple[_T_co | _T, ...]: ...
def __mul__(self, __n: SupportsIndex) -> tuple[_T_co, ...]: ...
def __rmul__(self, __n: SupportsIndex) -> tuple[_T_co, ...]: ...
def count(self, __value: Any) -> int: ...
def index(self, __value: Any, __start: SupportsIndex = ..., __stop: SupportsIndex = ...) -> int: ...
if sys.version_info >= (3, 9):
@@ -924,7 +923,7 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]):
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
class enumerate(Iterator[Tuple[int, _T]], Generic[_T]):
class enumerate(Iterator[tuple[int, _T]], Generic[_T]):
def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ...
def __iter__(self) -> Iterator[tuple[int, _T]]: ...
def __next__(self) -> tuple[int, _T]: ...
@@ -1090,15 +1089,15 @@ def iter(__function: Callable[[], _T], __sentinel: object) -> Iterator[_T]: ...
# We need recursive types to express the type of the second argument to `isinstance` properly, hence the use of `Any`
if sys.version_info >= (3, 10):
def isinstance(
__obj: object, __class_or_tuple: type | types.UnionType | Tuple[type | types.UnionType | Tuple[Any, ...], ...]
__obj: object, __class_or_tuple: type | types.UnionType | tuple[type | types.UnionType | tuple[Any, ...], ...]
) -> bool: ...
def issubclass(
__cls: type, __class_or_tuple: type | types.UnionType | Tuple[type | types.UnionType | Tuple[Any, ...], ...]
__cls: type, __class_or_tuple: type | types.UnionType | tuple[type | types.UnionType | tuple[Any, ...], ...]
) -> bool: ...
else:
def isinstance(__obj: object, __class_or_tuple: type | Tuple[type | Tuple[Any, ...], ...]) -> bool: ...
def issubclass(__cls: type, __class_or_tuple: type | Tuple[type | Tuple[Any, ...], ...]) -> bool: ...
def isinstance(__obj: object, __class_or_tuple: type | tuple[type | tuple[Any, ...], ...]) -> bool: ...
def issubclass(__cls: type, __class_or_tuple: type | tuple[type | tuple[Any, ...], ...]) -> bool: ...
def len(__obj: Sized) -> int: ...
def license() -> None: ...
@@ -1449,7 +1448,7 @@ class zip(Iterator[_T_co], Generic[_T_co]):
__iter6: Iterable[Any],
*iterables: Iterable[Any],
strict: bool = ...,
) -> zip[Tuple[Any, ...]]: ...
) -> zip[tuple[Any, ...]]: ...
else:
@overload
def __new__(cls, __iter1: Iterable[_T1]) -> zip[tuple[_T1]]: ...
@@ -1480,7 +1479,7 @@ class zip(Iterator[_T_co], Generic[_T_co]):
__iter5: Iterable[Any],
__iter6: Iterable[Any],
*iterables: Iterable[Any],
) -> zip[Tuple[Any, ...]]: ...
) -> zip[tuple[Any, ...]]: ...
def __iter__(self) -> Iterator[_T_co]: ...
def __next__(self) -> _T_co: ...
@@ -1502,7 +1501,7 @@ class ellipsis: ...
Ellipsis: ellipsis
class BaseException(object):
args: Tuple[Any, ...]
args: tuple[Any, ...]
__cause__: BaseException | None
__context__: BaseException | None
__suppress_context__: bool