Use typing_extensions.Self in the stdlib (#9694)

This commit is contained in:
Alex Waygood
2023-02-09 09:12:13 +00:00
committed by GitHub
parent 10086c06a1
commit 9ed39d8796
98 changed files with 627 additions and 654 deletions

View File

@@ -1,8 +1,7 @@
import sys
from _typeshed import Self
from collections.abc import Callable, Iterable, Iterator
from typing import Any, Generic, SupportsComplex, SupportsFloat, SupportsInt, TypeVar, overload
from typing_extensions import Literal, SupportsIndex, TypeAlias
from typing_extensions import Literal, Self, SupportsIndex, TypeAlias
if sys.version_info >= (3, 9):
from types import GenericAlias
@@ -32,12 +31,12 @@ class count(Iterator[_N], Generic[_N]):
@overload
def __new__(cls, *, step: _N) -> count[_N]: ...
def __next__(self) -> _N: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
class cycle(Iterator[_T], Generic[_T]):
def __init__(self, __iterable: Iterable[_T]) -> None: ...
def __next__(self) -> _T: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
class repeat(Iterator[_T], Generic[_T]):
@overload
@@ -45,7 +44,7 @@ class repeat(Iterator[_T], Generic[_T]):
@overload
def __init__(self, object: _T, times: int) -> None: ...
def __next__(self) -> _T: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __length_hint__(self) -> int: ...
class accumulate(Iterator[_T], Generic[_T]):
@@ -57,13 +56,13 @@ class accumulate(Iterator[_T], Generic[_T]):
else:
def __init__(self, iterable: Iterable[_T], func: Callable[[_T, _T], _T] | None = ...) -> None: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
class chain(Iterator[_T], Generic[_T]):
def __init__(self, *iterables: Iterable[_T]) -> None: ...
def __next__(self) -> _T: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
@classmethod
# We use type[Any] and not type[_S] to not lose the type inference from __iterable
def from_iterable(cls: type[Any], __iterable: Iterable[Iterable[_S]]) -> chain[_S]: ...
@@ -72,17 +71,17 @@ class chain(Iterator[_T], Generic[_T]):
class compress(Iterator[_T], Generic[_T]):
def __init__(self, data: Iterable[_T], selectors: Iterable[Any]) -> None: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
class dropwhile(Iterator[_T], Generic[_T]):
def __init__(self, __predicate: _Predicate[_T], __iterable: Iterable[_T]) -> None: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
class filterfalse(Iterator[_T], Generic[_T]):
def __init__(self, __predicate: _Predicate[_T] | None, __iterable: Iterable[_T]) -> None: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
class groupby(Iterator[tuple[_T, Iterator[_S]]], Generic[_T, _S]):
@@ -90,7 +89,7 @@ class groupby(Iterator[tuple[_T, Iterator[_S]]], Generic[_T, _S]):
def __new__(cls, iterable: Iterable[_T1], key: None = None) -> groupby[_T1, _T1]: ...
@overload
def __new__(cls, iterable: Iterable[_T1], key: Callable[[_T1], _T2]) -> groupby[_T2, _T1]: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> tuple[_T, Iterator[_S]]: ...
class islice(Iterator[_T], Generic[_T]):
@@ -98,17 +97,17 @@ class islice(Iterator[_T], Generic[_T]):
def __init__(self, __iterable: Iterable[_T], __stop: int | None) -> None: ...
@overload
def __init__(self, __iterable: Iterable[_T], __start: int | None, __stop: int | None, __step: int | None = ...) -> None: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
class starmap(Iterator[_T], Generic[_T]):
def __init__(self, __function: Callable[..., _T], __iterable: Iterable[Iterable[Any]]) -> None: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
class takewhile(Iterator[_T], Generic[_T]):
def __init__(self, __predicate: _Predicate[_T], __iterable: Iterable[_T]) -> None: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...
def tee(__iterable: Iterable[_T], __n: int = 2) -> tuple[Iterator[_T], ...]: ...
@@ -190,7 +189,7 @@ class zip_longest(Iterator[_T_co], Generic[_T_co]):
*iterables: Iterable[_T],
fillvalue: _T,
) -> zip_longest[tuple[_T, ...]]: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T_co: ...
class product(Iterator[_T_co], Generic[_T_co]):
@@ -239,12 +238,12 @@ class product(Iterator[_T_co], Generic[_T_co]):
def __new__(cls, *iterables: Iterable[_T1], repeat: int) -> product[tuple[_T1, ...]]: ...
@overload
def __new__(cls, *iterables: Iterable[Any], repeat: int = ...) -> product[tuple[Any, ...]]: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T_co: ...
class permutations(Iterator[tuple[_T, ...]], Generic[_T]):
def __init__(self, iterable: Iterable[_T], r: int | None = ...) -> None: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> tuple[_T, ...]: ...
class combinations(Iterator[_T_co], Generic[_T_co]):
@@ -258,22 +257,22 @@ class combinations(Iterator[_T_co], Generic[_T_co]):
def __new__(cls, iterable: Iterable[_T], r: Literal[5]) -> combinations[tuple[_T, _T, _T, _T, _T]]: ...
@overload
def __new__(cls, iterable: Iterable[_T], r: int) -> combinations[tuple[_T, ...]]: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T_co: ...
class combinations_with_replacement(Iterator[tuple[_T, ...]], Generic[_T]):
def __init__(self, iterable: Iterable[_T], r: int) -> None: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> tuple[_T, ...]: ...
if sys.version_info >= (3, 10):
class pairwise(Iterator[_T_co], Generic[_T_co]):
def __new__(cls, __iterable: Iterable[_T]) -> pairwise[tuple[_T, _T]]: ...
def __iter__(self: Self) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T_co: ...
if sys.version_info >= (3, 12):
class batched(Iterator[_T_co], Generic[_T_co]):
def __new__(cls: type[Self], iterable: Iterable[_T_co], n: int) -> Self: ...
def __iter__(self: Self) -> Self: ...
def __new__(cls, iterable: Iterable[_T_co], n: int) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> tuple[_T_co, ...]: ...