Use PEP 570 syntax in stdlib (#11250)

This commit is contained in:
Shantanu
2024-03-09 14:50:16 -08:00
committed by GitHub
parent 63737acac6
commit 470a13ab09
139 changed files with 2412 additions and 2371 deletions

View File

@@ -282,7 +282,7 @@ if sys.version_info >= (3, 10):
def __init__(self, name: str, tp: Any) -> None: ...
if sys.version_info >= (3, 11):
@staticmethod
def __call__(__x: _T) -> _T: ...
def __call__(x: _T, /) -> _T: ...
else:
def __call__(self, x: _T) -> _T: ...
@@ -372,7 +372,7 @@ class SupportsRound(Protocol[_T_co]):
def __round__(self) -> int: ...
@overload
@abstractmethod
def __round__(self, __ndigits: int) -> _T_co: ...
def __round__(self, ndigits: int, /) -> _T_co: ...
@runtime_checkable
class Sized(Protocol, metaclass=ABCMeta):
@@ -410,15 +410,15 @@ _ReturnT_co = TypeVar("_ReturnT_co", covariant=True)
class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _ReturnT_co]):
def __next__(self) -> _YieldT_co: ...
@abstractmethod
def send(self, __value: _SendT_contra) -> _YieldT_co: ...
def send(self, value: _SendT_contra, /) -> _YieldT_co: ...
@overload
@abstractmethod
def throw(
self, __typ: type[BaseException], __val: BaseException | object = None, __tb: TracebackType | None = None
self, typ: type[BaseException], val: BaseException | object = None, tb: TracebackType | None = None, /
) -> _YieldT_co: ...
@overload
@abstractmethod
def throw(self, __typ: BaseException, __val: None = None, __tb: TracebackType | None = None) -> _YieldT_co: ...
def throw(self, typ: BaseException, val: None = None, tb: TracebackType | None = None, /) -> _YieldT_co: ...
def close(self) -> None: ...
def __iter__(self) -> Generator[_YieldT_co, _SendT_contra, _ReturnT_co]: ...
@property
@@ -447,15 +447,15 @@ class Coroutine(Awaitable[_ReturnT_co], Generic[_YieldT_co, _SendT_contra, _Retu
@property
def cr_running(self) -> bool: ...
@abstractmethod
def send(self, __value: _SendT_contra) -> _YieldT_co: ...
def send(self, value: _SendT_contra, /) -> _YieldT_co: ...
@overload
@abstractmethod
def throw(
self, __typ: type[BaseException], __val: BaseException | object = None, __tb: TracebackType | None = None
self, typ: type[BaseException], val: BaseException | object = None, tb: TracebackType | None = None, /
) -> _YieldT_co: ...
@overload
@abstractmethod
def throw(self, __typ: BaseException, __val: None = None, __tb: TracebackType | None = None) -> _YieldT_co: ...
def throw(self, typ: BaseException, val: None = None, tb: TracebackType | None = None, /) -> _YieldT_co: ...
@abstractmethod
def close(self) -> None: ...
@@ -483,15 +483,15 @@ class AsyncIterator(AsyncIterable[_T_co], Protocol[_T_co]):
class AsyncGenerator(AsyncIterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra]):
def __anext__(self) -> Awaitable[_YieldT_co]: ...
@abstractmethod
def asend(self, __value: _SendT_contra) -> Awaitable[_YieldT_co]: ...
def asend(self, value: _SendT_contra, /) -> Awaitable[_YieldT_co]: ...
@overload
@abstractmethod
def athrow(
self, __typ: type[BaseException], __val: BaseException | object = None, __tb: TracebackType | None = None
self, typ: type[BaseException], val: BaseException | object = None, tb: TracebackType | None = None, /
) -> Awaitable[_YieldT_co]: ...
@overload
@abstractmethod
def athrow(self, __typ: BaseException, __val: None = None, __tb: TracebackType | None = None) -> Awaitable[_YieldT_co]: ...
def athrow(self, typ: BaseException, val: None = None, tb: TracebackType | None = None, /) -> Awaitable[_YieldT_co]: ...
def aclose(self) -> Awaitable[None]: ...
@property
def ag_await(self) -> Any: ...
@@ -506,7 +506,7 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Generic[_YieldT_co, _SendT_contr
class Container(Protocol[_T_co]):
# This is generic more on vibes than anything else
@abstractmethod
def __contains__(self, __x: object) -> bool: ...
def __contains__(self, x: object, /) -> bool: ...
@runtime_checkable
class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):
@@ -630,30 +630,30 @@ class Mapping(Collection[_KT], Generic[_KT, _VT_co]):
# TODO: We wish the key type could also be covariant, but that doesn't work,
# see discussion in https://github.com/python/typing/pull/273.
@abstractmethod
def __getitem__(self, __key: _KT) -> _VT_co: ...
def __getitem__(self, key: _KT, /) -> _VT_co: ...
# Mixin methods
@overload
def get(self, __key: _KT) -> _VT_co | None: ...
def get(self, key: _KT, /) -> _VT_co | None: ...
@overload
def get(self, __key: _KT, default: _VT_co | _T) -> _VT_co | _T: ...
def get(self, key: _KT, /, default: _VT_co | _T) -> _VT_co | _T: ...
def items(self) -> ItemsView[_KT, _VT_co]: ...
def keys(self) -> KeysView[_KT]: ...
def values(self) -> ValuesView[_VT_co]: ...
def __contains__(self, __key: object) -> bool: ...
def __eq__(self, __other: object) -> bool: ...
def __contains__(self, key: object, /) -> bool: ...
def __eq__(self, other: object, /) -> bool: ...
class MutableMapping(Mapping[_KT, _VT]):
@abstractmethod
def __setitem__(self, __key: _KT, __value: _VT) -> None: ...
def __setitem__(self, key: _KT, value: _VT, /) -> None: ...
@abstractmethod
def __delitem__(self, __key: _KT) -> None: ...
def __delitem__(self, key: _KT, /) -> None: ...
def clear(self) -> None: ...
@overload
def pop(self, __key: _KT) -> _VT: ...
def pop(self, key: _KT, /) -> _VT: ...
@overload
def pop(self, __key: _KT, default: _VT) -> _VT: ...
def pop(self, key: _KT, /, default: _VT) -> _VT: ...
@overload
def pop(self, __key: _KT, default: _T) -> _VT | _T: ...
def pop(self, key: _KT, /, default: _T) -> _VT | _T: ...
def popitem(self) -> tuple[_KT, _VT]: ...
# This overload should be allowed only if the value type is compatible with None.
#
@@ -662,9 +662,9 @@ class MutableMapping(Mapping[_KT, _VT]):
# -- collections.ChainMap.setdefault
# -- weakref.WeakKeyDictionary.setdefault
@overload
def setdefault(self: MutableMapping[_KT, _T | None], __key: _KT, __default: None = None) -> _T | None: ...
def setdefault(self: MutableMapping[_KT, _T | None], key: _KT, default: None = None, /) -> _T | None: ...
@overload
def setdefault(self, __key: _KT, __default: _VT) -> _VT: ...
def setdefault(self, key: _KT, default: _VT, /) -> _VT: ...
# 'update' used to take a Union, but using overloading is better.
# The second overloaded type here is a bit too general, because
# Mapping[tuple[_KT, _VT], W] is a subclass of Iterable[tuple[_KT, _VT]],
@@ -686,9 +686,9 @@ class MutableMapping(Mapping[_KT, _VT]):
# -- weakref.WeakValueDictionary.__ior__
# -- weakref.WeakKeyDictionary.__ior__
@overload
def update(self, __m: SupportsKeysAndGetItem[_KT, _VT], **kwargs: _VT) -> None: ...
def update(self, m: SupportsKeysAndGetItem[_KT, _VT], /, **kwargs: _VT) -> None: ...
@overload
def update(self, __m: Iterable[tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
def update(self, m: Iterable[tuple[_KT, _VT]], /, **kwargs: _VT) -> None: ...
@overload
def update(self, **kwargs: _VT) -> None: ...
@@ -720,41 +720,41 @@ class IO(Iterator[AnyStr]):
@abstractmethod
def isatty(self) -> bool: ...
@abstractmethod
def read(self, __n: int = -1) -> AnyStr: ...
def read(self, n: int = -1, /) -> AnyStr: ...
@abstractmethod
def readable(self) -> bool: ...
@abstractmethod
def readline(self, __limit: int = -1) -> AnyStr: ...
def readline(self, limit: int = -1, /) -> AnyStr: ...
@abstractmethod
def readlines(self, __hint: int = -1) -> list[AnyStr]: ...
def readlines(self, hint: int = -1, /) -> list[AnyStr]: ...
@abstractmethod
def seek(self, __offset: int, __whence: int = 0) -> int: ...
def seek(self, offset: int, whence: int = 0, /) -> int: ...
@abstractmethod
def seekable(self) -> bool: ...
@abstractmethod
def tell(self) -> int: ...
@abstractmethod
def truncate(self, __size: int | None = None) -> int: ...
def truncate(self, size: int | None = None, /) -> int: ...
@abstractmethod
def writable(self) -> bool: ...
@abstractmethod
@overload
def write(self: IO[str], __s: str) -> int: ...
def write(self: IO[str], s: str, /) -> int: ...
@abstractmethod
@overload
def write(self: IO[bytes], __s: ReadableBuffer) -> int: ...
def write(self: IO[bytes], s: ReadableBuffer, /) -> int: ...
@abstractmethod
@overload
def write(self, __s: AnyStr) -> int: ...
def write(self, s: AnyStr, /) -> int: ...
@abstractmethod
@overload
def writelines(self: IO[str], __lines: Iterable[str]) -> None: ...
def writelines(self: IO[str], lines: Iterable[str], /) -> None: ...
@abstractmethod
@overload
def writelines(self: IO[bytes], __lines: Iterable[ReadableBuffer]) -> None: ...
def writelines(self: IO[bytes], lines: Iterable[ReadableBuffer], /) -> None: ...
@abstractmethod
@overload
def writelines(self, __lines: Iterable[AnyStr]) -> None: ...
def writelines(self, lines: Iterable[AnyStr], /) -> None: ...
@abstractmethod
def __next__(self) -> AnyStr: ...
@abstractmethod
@@ -763,7 +763,7 @@ class IO(Iterator[AnyStr]):
def __enter__(self) -> IO[AnyStr]: ...
@abstractmethod
def __exit__(
self, __type: type[BaseException] | None, __value: BaseException | None, __traceback: TracebackType | None
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None, /
) -> None: ...
class BinaryIO(IO[bytes]):
@@ -839,9 +839,9 @@ def cast(typ: str, val: Any) -> Any: ...
def cast(typ: object, val: Any) -> Any: ...
if sys.version_info >= (3, 11):
def reveal_type(__obj: _T) -> _T: ...
def assert_never(__arg: Never) -> Never: ...
def assert_type(__val: _T, __typ: Any) -> _T: ...
def reveal_type(obj: _T, /) -> _T: ...
def assert_never(arg: Never, /) -> Never: ...
def assert_type(val: _T, typ: Any, /) -> _T: ...
def clear_overloads() -> None: ...
def get_overloads(func: Callable[..., object]) -> Sequence[Callable[..., object]]: ...
def dataclass_transform(
@@ -867,9 +867,9 @@ class NamedTuple(tuple[Any, ...]):
__orig_bases__: ClassVar[tuple[Any, ...]]
@overload
def __init__(self, __typename: str, __fields: Iterable[tuple[str, Any]]) -> None: ...
def __init__(self, typename: str, fields: Iterable[tuple[str, Any]], /) -> None: ...
@overload
def __init__(self, __typename: str, __fields: None = None, **kwargs: Any) -> None: ...
def __init__(self, typename: str, fields: None = None, /, **kwargs: Any) -> None: ...
@classmethod
def _make(cls, iterable: Iterable[Any]) -> typing_extensions.Self: ...
def _asdict(self) -> dict[str, Any]: ...
@@ -894,22 +894,22 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
def setdefault(self, k: _Never, default: object) -> object: ...
# Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
def pop(self, k: _Never, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
def update(self: _T, __m: _T) -> None: ...
def update(self: _T, m: _T, /) -> None: ...
def __delitem__(self, k: _Never) -> None: ...
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: ...
def __or__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ...
@overload
def __or__(self, __value: dict[str, Any]) -> dict[str, object]: ...
def __or__(self, value: dict[str, Any], /) -> dict[str, object]: ...
@overload
def __ror__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ...
def __ror__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ...
@overload
def __ror__(self, __value: dict[str, Any]) -> dict[str, object]: ...
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]
def __ior__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ... # type: ignore[misc]
@final
class ForwardRef:
@@ -945,7 +945,7 @@ if sys.version_info >= (3, 10):
def _type_repr(obj: object) -> str: ...
if sys.version_info >= (3, 12):
def override(__method: _F) -> _F: ...
def override(method: _F, /) -> _F: ...
@final
class TypeAliasType:
def __init__(
@@ -967,5 +967,5 @@ if sys.version_info >= (3, 12):
def __ror__(self, left: Any) -> _SpecialForm: ...
if sys.version_info >= (3, 13):
def is_protocol(__tp: type) -> bool: ...
def get_protocol_members(__tp: type) -> frozenset[str]: ...
def is_protocol(tp: type, /) -> bool: ...
def get_protocol_members(tp: type, /) -> frozenset[str]: ...