2 from _typeshed import _T_co
18 from typing_extensions import Literal, SupportsIndex
22 _N = TypeVar("_N", int, float, SupportsFloat, SupportsInt, SupportsIndex, SupportsComplex)
23 _Step = Union[int, float, SupportsFloat, SupportsInt, SupportsIndex, SupportsComplex]
25 Predicate = Callable[[_T], object]
27 # Technically count can take anything that implements a number protocol and has an add method
28 # but we can't enforce the add method
29 class count(Iterator[_N], Generic[_N]):
31 def __new__(cls) -> count[int]: ...
33 def __new__(cls, start: _N, step: _Step = ...) -> count[_N]: ...
35 def __new__(cls, *, step: _N) -> count[_N]: ...
36 def __next__(self) -> _N: ...
37 def __iter__(self) -> Iterator[_N]: ...
39 class cycle(Iterator[_T], Generic[_T]):
40 def __init__(self, __iterable: Iterable[_T]) -> None: ...
41 def __next__(self) -> _T: ...
42 def __iter__(self) -> Iterator[_T]: ...
44 class repeat(Iterator[_T], Generic[_T]):
46 def __init__(self, object: _T) -> None: ...
48 def __init__(self, object: _T, times: int) -> None: ...
49 def __next__(self) -> _T: ...
50 def __iter__(self) -> Iterator[_T]: ...
52 class accumulate(Iterator[_T], Generic[_T]):
53 if sys.version_info >= (3, 8):
55 def __init__(self, iterable: Iterable[_T], func: None = ..., *, initial: _T | None = ...) -> None: ...
57 def __init__(self, iterable: Iterable[_S], func: Callable[[_T, _S], _T], *, initial: _T | None = ...) -> None: ...
59 def __init__(self, iterable: Iterable[_T], func: Callable[[_T, _T], _T] | None = ...) -> None: ...
60 def __iter__(self) -> Iterator[_T]: ...
61 def __next__(self) -> _T: ...
63 class chain(Iterator[_T], Generic[_T]):
64 def __init__(self, *iterables: Iterable[_T]) -> None: ...
65 def __next__(self) -> _T: ...
66 def __iter__(self) -> Iterator[_T]: ...
68 # We use Type and not Type[_S] to not lose the type inference from __iterable
69 def from_iterable(cls: Type[Any], __iterable: Iterable[Iterable[_S]]) -> Iterator[_S]: ...
71 class compress(Iterator[_T], Generic[_T]):
72 def __init__(self, data: Iterable[_T], selectors: Iterable[Any]) -> None: ...
73 def __iter__(self) -> Iterator[_T]: ...
74 def __next__(self) -> _T: ...
76 class dropwhile(Iterator[_T], Generic[_T]):
77 def __init__(self, __predicate: Predicate[_T], __iterable: Iterable[_T]) -> None: ...
78 def __iter__(self) -> Iterator[_T]: ...
79 def __next__(self) -> _T: ...
81 class filterfalse(Iterator[_T], Generic[_T]):
82 def __init__(self, __predicate: Predicate[_T] | None, __iterable: Iterable[_T]) -> None: ...
83 def __iter__(self) -> Iterator[_T]: ...
84 def __next__(self) -> _T: ...
89 class groupby(Iterator[Tuple[_T, Iterator[_S]]], Generic[_T, _S]):
91 def __new__(cls, iterable: Iterable[_T1], key: None = ...) -> groupby[_T1, _T1]: ...
93 def __new__(cls, iterable: Iterable[_T1], key: Callable[[_T1], _T2]) -> groupby[_T2, _T1]: ...
94 def __iter__(self) -> Iterator[tuple[_T, Iterator[_S]]]: ...
95 def __next__(self) -> tuple[_T, Iterator[_S]]: ...
97 class islice(Iterator[_T], Generic[_T]):
99 def __init__(self, __iterable: Iterable[_T], __stop: int | None) -> None: ...
101 def __init__(self, __iterable: Iterable[_T], __start: int | None, __stop: int | None, __step: int | None = ...) -> None: ...
102 def __iter__(self) -> Iterator[_T]: ...
103 def __next__(self) -> _T: ...
105 class starmap(Iterator[_T], Generic[_T]):
106 def __init__(self, __function: Callable[..., _T], __iterable: Iterable[Iterable[Any]]) -> None: ...
107 def __iter__(self) -> Iterator[_T]: ...
108 def __next__(self) -> _T: ...
110 class takewhile(Iterator[_T], Generic[_T]):
111 def __init__(self, __predicate: Predicate[_T], __iterable: Iterable[_T]) -> None: ...
112 def __iter__(self) -> Iterator[_T]: ...
113 def __next__(self) -> _T: ...
115 def tee(__iterable: Iterable[_T], __n: int = ...) -> Tuple[Iterator[_T], ...]: ...
117 class zip_longest(Iterator[Any]):
118 def __init__(self, *p: Iterable[Any], fillvalue: Any = ...) -> None: ...
119 def __iter__(self) -> Iterator[Any]: ...
120 def __next__(self) -> Any: ...
127 class product(Iterator[_T_co], Generic[_T_co]):
129 def __new__(cls, __iter1: Iterable[_T1]) -> product[tuple[_T1]]: ...
131 def __new__(cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> product[tuple[_T1, _T2]]: ...
133 def __new__(cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3]) -> product[tuple[_T1, _T2, _T3]]: ...
136 cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3], __iter4: Iterable[_T4]
137 ) -> product[tuple[_T1, _T2, _T3, _T4]]: ...
141 __iter1: Iterable[_T1],
142 __iter2: Iterable[_T2],
143 __iter3: Iterable[_T3],
144 __iter4: Iterable[_T4],
145 __iter5: Iterable[_T5],
146 ) -> product[tuple[_T1, _T2, _T3, _T4, _T5]]: ...
150 __iter1: Iterable[_T1],
151 __iter2: Iterable[_T2],
152 __iter3: Iterable[_T3],
153 __iter4: Iterable[_T4],
154 __iter5: Iterable[_T5],
155 __iter6: Iterable[_T6],
156 ) -> product[tuple[_T1, _T2, _T3, _T4, _T5, _T6]]: ...
160 __iter1: Iterable[Any],
161 __iter2: Iterable[Any],
162 __iter3: Iterable[Any],
163 __iter4: Iterable[Any],
164 __iter5: Iterable[Any],
165 __iter6: Iterable[Any],
166 __iter7: Iterable[Any],
167 *iterables: Iterable[Any],
168 ) -> product[Tuple[Any, ...]]: ...
170 def __new__(cls, *iterables: Iterable[_T1], repeat: int) -> product[Tuple[_T1, ...]]: ...
172 def __new__(cls, *iterables: Iterable[Any], repeat: int = ...) -> product[Tuple[Any, ...]]: ...
173 def __iter__(self) -> Iterator[_T_co]: ...
174 def __next__(self) -> _T_co: ...
176 class permutations(Iterator[Tuple[_T, ...]], Generic[_T]):
177 def __init__(self, iterable: Iterable[_T], r: int | None = ...) -> None: ...
178 def __iter__(self) -> Iterator[Tuple[_T, ...]]: ...
179 def __next__(self) -> Tuple[_T, ...]: ...
181 class combinations(Iterator[_T_co], Generic[_T_co]):
183 def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations[tuple[_T, _T]]: ...
185 def __new__(cls, iterable: Iterable[_T], r: Literal[3]) -> combinations[tuple[_T, _T, _T]]: ...
187 def __new__(cls, iterable: Iterable[_T], r: Literal[4]) -> combinations[tuple[_T, _T, _T, _T]]: ...
189 def __new__(cls, iterable: Iterable[_T], r: Literal[5]) -> combinations[tuple[_T, _T, _T, _T, _T]]: ...
191 def __new__(cls, iterable: Iterable[_T], r: int) -> combinations[Tuple[_T, ...]]: ...
192 def __iter__(self) -> Iterator[_T_co]: ...
193 def __next__(self) -> _T_co: ...
195 class combinations_with_replacement(Iterator[Tuple[_T, ...]], Generic[_T]):
196 def __init__(self, iterable: Iterable[_T], r: int) -> None: ...
197 def __iter__(self) -> Iterator[Tuple[_T, ...]]: ...
198 def __next__(self) -> Tuple[_T, ...]: ...
200 if sys.version_info >= (3, 10):
201 class pairwise(Iterator[_T_co], Generic[_T_co]):
202 def __new__(cls, __iterable: Iterable[_T]) -> pairwise[tuple[_T, _T]]: ...
203 def __iter__(self) -> Iterator[_T_co]: ...
204 def __next__(self) -> _T_co: ...