Skip to content

Improve itertools stubs #7109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions stdlib/itertools.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from _typeshed import _T_co
from _typeshed import Self, _T_co
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -35,20 +35,20 @@ class count(Iterator[_N], Generic[_N]):
@overload
def __new__(cls, *, step: _N) -> count[_N]: ...
def __next__(self) -> _N: ...
def __iter__(self) -> Iterator[_N]: ...
def __iter__(self: Self) -> Self: ...

class cycle(Iterator[_T], Generic[_T]):
def __init__(self, __iterable: Iterable[_T]) -> None: ...
def __next__(self) -> _T: ...
def __iter__(self) -> Iterator[_T]: ...
def __iter__(self: Self) -> Self: ...

class repeat(Iterator[_T], Generic[_T]):
@overload
def __init__(self, object: _T) -> None: ...
@overload
def __init__(self, object: _T, times: int) -> None: ...
def __next__(self) -> _T: ...
def __iter__(self) -> Iterator[_T]: ...
def __iter__(self: Self) -> Self: ...

class accumulate(Iterator[_T], Generic[_T]):
if sys.version_info >= (3, 8):
Expand All @@ -59,32 +59,32 @@ class accumulate(Iterator[_T], Generic[_T]):
else:
def __init__(self, iterable: Iterable[_T], func: Callable[[_T, _T], _T] | None = ...) -> None: ...

def __iter__(self) -> Iterator[_T]: ...
def __iter__(self: 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) -> Iterator[_T]: ...
def __iter__(self: Self) -> Self: ...
@classmethod
# We use Type and not Type[_S] to not lose the type inference from __iterable
def from_iterable(cls: type[Any], __iterable: Iterable[Iterable[_S]]) -> Iterator[_S]: ...
# 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]: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...

class compress(Iterator[_T], Generic[_T]):
def __init__(self, data: Iterable[_T], selectors: Iterable[Any]) -> None: ...
def __iter__(self) -> Iterator[_T]: ...
def __iter__(self: 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) -> Iterator[_T]: ...
def __iter__(self: 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) -> Iterator[_T]: ...
def __iter__(self: Self) -> Self: ...
def __next__(self) -> _T: ...

_T1 = TypeVar("_T1")
Expand All @@ -95,32 +95,32 @@ class groupby(Iterator[tuple[_T, Iterator[_S]]], Generic[_T, _S]):
def __new__(cls, iterable: Iterable[_T1], key: None = ...) -> groupby[_T1, _T1]: ...
@overload
def __new__(cls, iterable: Iterable[_T1], key: Callable[[_T1], _T2]) -> groupby[_T2, _T1]: ...
def __iter__(self) -> Iterator[tuple[_T, Iterator[_S]]]: ...
def __iter__(self: Self) -> Self: ...
def __next__(self) -> tuple[_T, Iterator[_S]]: ...

class islice(Iterator[_T], Generic[_T]):
@overload
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) -> Iterator[_T]: ...
def __iter__(self: 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) -> Iterator[_T]: ...
def __iter__(self: 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) -> Iterator[_T]: ...
def __iter__(self: Self) -> Self: ...
def __next__(self) -> _T: ...

def tee(__iterable: Iterable[_T], __n: int = ...) -> tuple[Iterator[_T], ...]: ...

class zip_longest(Iterator[Any]):
def __init__(self, *p: Iterable[Any], fillvalue: Any = ...) -> None: ...
def __iter__(self) -> Iterator[Any]: ...
def __iter__(self: Self) -> Self: ...
def __next__(self) -> Any: ...

_T3 = TypeVar("_T3")
Expand Down Expand Up @@ -174,12 +174,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) -> Iterator[_T_co]: ...
def __iter__(self: 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) -> Iterator[tuple[_T, ...]]: ...
def __iter__(self: Self) -> Self: ...
def __next__(self) -> tuple[_T, ...]: ...

class combinations(Iterator[_T_co], Generic[_T_co]):
Expand All @@ -193,16 +193,16 @@ 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) -> Iterator[_T_co]: ...
def __iter__(self: 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) -> Iterator[tuple[_T, ...]]: ...
def __iter__(self: 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) -> Iterator[_T_co]: ...
def __iter__(self: Self) -> Self: ...
def __next__(self) -> _T_co: ...