| 1 |
import sys |
| 2 |
from _typeshed import MaybeNone |
| 3 |
from collections.abc import Callable, Iterable, Iterator |
| 4 |
from types import GenericAlias |
| 5 |
from typing import Any, Generic, Literal, SupportsComplex, SupportsFloat, SupportsIndex, SupportsInt, TypeVar, overload |
| 6 |
from typing_extensions import Self, TypeAlias, disjoint_base |
| 7 |
|
| 8 |
_T = TypeVar("_T") |
| 9 |
_S = TypeVar("_S") |
| 10 |
_N = TypeVar("_N", int, float, SupportsFloat, SupportsInt, SupportsIndex, SupportsComplex) |
| 11 |
_T_co = TypeVar("_T_co", covariant=True) |
| 12 |
_S_co = TypeVar("_S_co", covariant=True) |
| 13 |
_T1 = TypeVar("_T1") |
| 14 |
_T2 = TypeVar("_T2") |
| 15 |
_T3 = TypeVar("_T3") |
| 16 |
_T4 = TypeVar("_T4") |
| 17 |
_T5 = TypeVar("_T5") |
| 18 |
_T6 = TypeVar("_T6") |
| 19 |
_T7 = TypeVar("_T7") |
| 20 |
_T8 = TypeVar("_T8") |
| 21 |
_T9 = TypeVar("_T9") |
| 22 |
_T10 = TypeVar("_T10") |
| 23 |
|
| 24 |
_Step: TypeAlias = SupportsFloat | SupportsInt | SupportsIndex | SupportsComplex |
| 25 |
|
| 26 |
_Predicate: TypeAlias = Callable[[_T], object] |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
@disjoint_base |
| 31 |
class count(Generic[_N]): |
| 32 |
@overload |
| 33 |
def __new__(cls) -> count[int]: ... |
| 34 |
@overload |
| 35 |
def __new__(cls, start: _N, step: _Step = 1) -> count[_N]: ... |
| 36 |
@overload |
| 37 |
def __new__(cls, *, step: _N) -> count[_N]: ... |
| 38 |
def __next__(self) -> _N: ... |
| 39 |
def __iter__(self) -> Self: ... |
| 40 |
|
| 41 |
@disjoint_base |
| 42 |
class cycle(Generic[_T]): |
| 43 |
def __new__(cls, iterable: Iterable[_T], /) -> Self: ... |
| 44 |
def __next__(self) -> _T: ... |
| 45 |
def __iter__(self) -> Self: ... |
| 46 |
|
| 47 |
@disjoint_base |
| 48 |
class repeat(Generic[_T]): |
| 49 |
@overload |
| 50 |
def __new__(cls, object: _T) -> Self: ... |
| 51 |
@overload |
| 52 |
def __new__(cls, object: _T, times: int) -> Self: ... |
| 53 |
def __next__(self) -> _T: ... |
| 54 |
def __iter__(self) -> Self: ... |
| 55 |
def __length_hint__(self) -> int: ... |
| 56 |
|
| 57 |
@disjoint_base |
| 58 |
class accumulate(Generic[_T]): |
| 59 |
@overload |
| 60 |
def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = None) -> Self: ... |
| 61 |
@overload |
| 62 |
def __new__(cls, iterable: Iterable[_S], func: Callable[[_T, _S], _T], *, initial: _T | None = None) -> Self: ... |
| 63 |
def __iter__(self) -> Self: ... |
| 64 |
def __next__(self) -> _T: ... |
| 65 |
|
| 66 |
@disjoint_base |
| 67 |
class chain(Generic[_T]): |
| 68 |
def __new__(cls, *iterables: Iterable[_T]) -> Self: ... |
| 69 |
def __next__(self) -> _T: ... |
| 70 |
def __iter__(self) -> Self: ... |
| 71 |
@classmethod |
| 72 |
|
| 73 |
def from_iterable(cls: type[Any], iterable: Iterable[Iterable[_S]], /) -> chain[_S]: ... |
| 74 |
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... |
| 75 |
|
| 76 |
@disjoint_base |
| 77 |
class compress(Generic[_T]): |
| 78 |
def __new__(cls, data: Iterable[_T], selectors: Iterable[Any]) -> Self: ... |
| 79 |
def __iter__(self) -> Self: ... |
| 80 |
def __next__(self) -> _T: ... |
| 81 |
|
| 82 |
@disjoint_base |
| 83 |
class dropwhile(Generic[_T]): |
| 84 |
def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ... |
| 85 |
def __iter__(self) -> Self: ... |
| 86 |
def __next__(self) -> _T: ... |
| 87 |
|
| 88 |
@disjoint_base |
| 89 |
class filterfalse(Generic[_T]): |
| 90 |
def __new__(cls, function: _Predicate[_T] | None, iterable: Iterable[_T], /) -> Self: ... |
| 91 |
def __iter__(self) -> Self: ... |
| 92 |
def __next__(self) -> _T: ... |
| 93 |
|
| 94 |
@disjoint_base |
| 95 |
class groupby(Generic[_T_co, _S_co]): |
| 96 |
@overload |
| 97 |
def __new__(cls, iterable: Iterable[_T1], key: None = None) -> groupby[_T1, _T1]: ... |
| 98 |
@overload |
| 99 |
def __new__(cls, iterable: Iterable[_T1], key: Callable[[_T1], _T2]) -> groupby[_T2, _T1]: ... |
| 100 |
def __iter__(self) -> Self: ... |
| 101 |
def __next__(self) -> tuple[_T_co, Iterator[_S_co]]: ... |
| 102 |
|
| 103 |
@disjoint_base |
| 104 |
class islice(Generic[_T]): |
| 105 |
@overload |
| 106 |
def __new__(cls, iterable: Iterable[_T], stop: int | None, /) -> Self: ... |
| 107 |
@overload |
| 108 |
def __new__(cls, iterable: Iterable[_T], start: int | None, stop: int | None, step: int | None = 1, /) -> Self: ... |
| 109 |
def __iter__(self) -> Self: ... |
| 110 |
def __next__(self) -> _T: ... |
| 111 |
|
| 112 |
@disjoint_base |
| 113 |
class starmap(Generic[_T_co]): |
| 114 |
def __new__(cls, function: Callable[..., _T], iterable: Iterable[Iterable[Any]], /) -> starmap[_T]: ... |
| 115 |
def __iter__(self) -> Self: ... |
| 116 |
def __next__(self) -> _T_co: ... |
| 117 |
|
| 118 |
@disjoint_base |
| 119 |
class takewhile(Generic[_T]): |
| 120 |
def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ... |
| 121 |
def __iter__(self) -> Self: ... |
| 122 |
def __next__(self) -> _T: ... |
| 123 |
|
| 124 |
def tee(iterable: Iterable[_T], n: int = 2, /) -> tuple[Iterator[_T], ...]: ... |
| 125 |
@disjoint_base |
| 126 |
class zip_longest(Generic[_T_co]): |
| 127 |
|
| 128 |
@overload |
| 129 |
def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = None) -> zip_longest[tuple[_T1]]: ... |
| 130 |
|
| 131 |
@overload |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
def __new__(cls, iter1: Iterable[_T1], iter2: Iterable[_T2], /) -> zip_longest[tuple[_T1 | MaybeNone, _T2 | MaybeNone]]: ... |
| 136 |
@overload |
| 137 |
def __new__( |
| 138 |
cls, iter1: Iterable[_T1], iter2: Iterable[_T2], /, *, fillvalue: _T |
| 139 |
) -> zip_longest[tuple[_T1 | _T, _T2 | _T]]: ... |
| 140 |
|
| 141 |
@overload |
| 142 |
def __new__( |
| 143 |
cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], / |
| 144 |
) -> zip_longest[tuple[_T1 | MaybeNone, _T2 | MaybeNone, _T3 | MaybeNone]]: ... |
| 145 |
@overload |
| 146 |
def __new__( |
| 147 |
cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], /, *, fillvalue: _T |
| 148 |
) -> zip_longest[tuple[_T1 | _T, _T2 | _T, _T3 | _T]]: ... |
| 149 |
|
| 150 |
@overload |
| 151 |
def __new__( |
| 152 |
cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4], / |
| 153 |
) -> zip_longest[tuple[_T1 | MaybeNone, _T2 | MaybeNone, _T3 | MaybeNone, _T4 | MaybeNone]]: ... |
| 154 |
@overload |
| 155 |
def __new__( |
| 156 |
cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4], /, *, fillvalue: _T |
| 157 |
) -> zip_longest[tuple[_T1 | _T, _T2 | _T, _T3 | _T, _T4 | _T]]: ... |
| 158 |
|
| 159 |
@overload |
| 160 |
def __new__( |
| 161 |
cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4], iter5: Iterable[_T5], / |
| 162 |
) -> zip_longest[tuple[_T1 | MaybeNone, _T2 | MaybeNone, _T3 | MaybeNone, _T4 | MaybeNone, _T5 | MaybeNone]]: ... |
| 163 |
@overload |
| 164 |
def __new__( |
| 165 |
cls, |
| 166 |
iter1: Iterable[_T1], |
| 167 |
iter2: Iterable[_T2], |
| 168 |
iter3: Iterable[_T3], |
| 169 |
iter4: Iterable[_T4], |
| 170 |
iter5: Iterable[_T5], |
| 171 |
/, |
| 172 |
*, |
| 173 |
fillvalue: _T, |
| 174 |
) -> zip_longest[tuple[_T1 | _T, _T2 | _T, _T3 | _T, _T4 | _T, _T5 | _T]]: ... |
| 175 |
|
| 176 |
@overload |
| 177 |
def __new__( |
| 178 |
cls, |
| 179 |
iter1: Iterable[_T], |
| 180 |
iter2: Iterable[_T], |
| 181 |
iter3: Iterable[_T], |
| 182 |
iter4: Iterable[_T], |
| 183 |
iter5: Iterable[_T], |
| 184 |
iter6: Iterable[_T], |
| 185 |
/, |
| 186 |
*iterables: Iterable[_T], |
| 187 |
) -> zip_longest[tuple[_T | MaybeNone, ...]]: ... |
| 188 |
@overload |
| 189 |
def __new__( |
| 190 |
cls, |
| 191 |
iter1: Iterable[_T], |
| 192 |
iter2: Iterable[_T], |
| 193 |
iter3: Iterable[_T], |
| 194 |
iter4: Iterable[_T], |
| 195 |
iter5: Iterable[_T], |
| 196 |
iter6: Iterable[_T], |
| 197 |
/, |
| 198 |
*iterables: Iterable[_T], |
| 199 |
fillvalue: _T, |
| 200 |
) -> zip_longest[tuple[_T, ...]]: ... |
| 201 |
def __iter__(self) -> Self: ... |
| 202 |
def __next__(self) -> _T_co: ... |
| 203 |
|
| 204 |
@disjoint_base |
| 205 |
class product(Generic[_T_co]): |
| 206 |
@overload |
| 207 |
def __new__(cls, iter1: Iterable[_T1], /) -> product[tuple[_T1]]: ... |
| 208 |
@overload |
| 209 |
def __new__(cls, iter1: Iterable[_T1], iter2: Iterable[_T2], /) -> product[tuple[_T1, _T2]]: ... |
| 210 |
@overload |
| 211 |
def __new__(cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], /) -> product[tuple[_T1, _T2, _T3]]: ... |
| 212 |
@overload |
| 213 |
def __new__( |
| 214 |
cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4], / |
| 215 |
) -> product[tuple[_T1, _T2, _T3, _T4]]: ... |
| 216 |
@overload |
| 217 |
def __new__( |
| 218 |
cls, iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4], iter5: Iterable[_T5], / |
| 219 |
) -> product[tuple[_T1, _T2, _T3, _T4, _T5]]: ... |
| 220 |
@overload |
| 221 |
def __new__( |
| 222 |
cls, |
| 223 |
iter1: Iterable[_T1], |
| 224 |
iter2: Iterable[_T2], |
| 225 |
iter3: Iterable[_T3], |
| 226 |
iter4: Iterable[_T4], |
| 227 |
iter5: Iterable[_T5], |
| 228 |
iter6: Iterable[_T6], |
| 229 |
/, |
| 230 |
) -> product[tuple[_T1, _T2, _T3, _T4, _T5, _T6]]: ... |
| 231 |
@overload |
| 232 |
def __new__( |
| 233 |
cls, |
| 234 |
iter1: Iterable[_T1], |
| 235 |
iter2: Iterable[_T2], |
| 236 |
iter3: Iterable[_T3], |
| 237 |
iter4: Iterable[_T4], |
| 238 |
iter5: Iterable[_T5], |
| 239 |
iter6: Iterable[_T6], |
| 240 |
iter7: Iterable[_T7], |
| 241 |
/, |
| 242 |
) -> product[tuple[_T1, _T2, _T3, _T4, _T5, _T6, _T7]]: ... |
| 243 |
@overload |
| 244 |
def __new__( |
| 245 |
cls, |
| 246 |
iter1: Iterable[_T1], |
| 247 |
iter2: Iterable[_T2], |
| 248 |
iter3: Iterable[_T3], |
| 249 |
iter4: Iterable[_T4], |
| 250 |
iter5: Iterable[_T5], |
| 251 |
iter6: Iterable[_T6], |
| 252 |
iter7: Iterable[_T7], |
| 253 |
iter8: Iterable[_T8], |
| 254 |
/, |
| 255 |
) -> product[tuple[_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8]]: ... |
| 256 |
@overload |
| 257 |
def __new__( |
| 258 |
cls, |
| 259 |
iter1: Iterable[_T1], |
| 260 |
iter2: Iterable[_T2], |
| 261 |
iter3: Iterable[_T3], |
| 262 |
iter4: Iterable[_T4], |
| 263 |
iter5: Iterable[_T5], |
| 264 |
iter6: Iterable[_T6], |
| 265 |
iter7: Iterable[_T7], |
| 266 |
iter8: Iterable[_T8], |
| 267 |
iter9: Iterable[_T9], |
| 268 |
/, |
| 269 |
) -> product[tuple[_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9]]: ... |
| 270 |
@overload |
| 271 |
def __new__( |
| 272 |
cls, |
| 273 |
iter1: Iterable[_T1], |
| 274 |
iter2: Iterable[_T2], |
| 275 |
iter3: Iterable[_T3], |
| 276 |
iter4: Iterable[_T4], |
| 277 |
iter5: Iterable[_T5], |
| 278 |
iter6: Iterable[_T6], |
| 279 |
iter7: Iterable[_T7], |
| 280 |
iter8: Iterable[_T8], |
| 281 |
iter9: Iterable[_T9], |
| 282 |
iter10: Iterable[_T10], |
| 283 |
/, |
| 284 |
) -> product[tuple[_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10]]: ... |
| 285 |
@overload |
| 286 |
def __new__(cls, *iterables: Iterable[_T1], repeat: int = 1) -> product[tuple[_T1, ...]]: ... |
| 287 |
def __iter__(self) -> Self: ... |
| 288 |
def __next__(self) -> _T_co: ... |
| 289 |
|
| 290 |
@disjoint_base |
| 291 |
class permutations(Generic[_T_co]): |
| 292 |
@overload |
| 293 |
def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> permutations[tuple[_T, _T]]: ... |
| 294 |
@overload |
| 295 |
def __new__(cls, iterable: Iterable[_T], r: Literal[3]) -> permutations[tuple[_T, _T, _T]]: ... |
| 296 |
@overload |
| 297 |
def __new__(cls, iterable: Iterable[_T], r: Literal[4]) -> permutations[tuple[_T, _T, _T, _T]]: ... |
| 298 |
@overload |
| 299 |
def __new__(cls, iterable: Iterable[_T], r: Literal[5]) -> permutations[tuple[_T, _T, _T, _T, _T]]: ... |
| 300 |
@overload |
| 301 |
def __new__(cls, iterable: Iterable[_T], r: int | None = None) -> permutations[tuple[_T, ...]]: ... |
| 302 |
def __iter__(self) -> Self: ... |
| 303 |
def __next__(self) -> _T_co: ... |
| 304 |
|
| 305 |
@disjoint_base |
| 306 |
class combinations(Generic[_T_co]): |
| 307 |
@overload |
| 308 |
def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations[tuple[_T, _T]]: ... |
| 309 |
@overload |
| 310 |
def __new__(cls, iterable: Iterable[_T], r: Literal[3]) -> combinations[tuple[_T, _T, _T]]: ... |
| 311 |
@overload |
| 312 |
def __new__(cls, iterable: Iterable[_T], r: Literal[4]) -> combinations[tuple[_T, _T, _T, _T]]: ... |
| 313 |
@overload |
| 314 |
def __new__(cls, iterable: Iterable[_T], r: Literal[5]) -> combinations[tuple[_T, _T, _T, _T, _T]]: ... |
| 315 |
@overload |
| 316 |
def __new__(cls, iterable: Iterable[_T], r: int) -> combinations[tuple[_T, ...]]: ... |
| 317 |
def __iter__(self) -> Self: ... |
| 318 |
def __next__(self) -> _T_co: ... |
| 319 |
|
| 320 |
@disjoint_base |
| 321 |
class combinations_with_replacement(Generic[_T_co]): |
| 322 |
@overload |
| 323 |
def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations_with_replacement[tuple[_T, _T]]: ... |
| 324 |
@overload |
| 325 |
def __new__(cls, iterable: Iterable[_T], r: Literal[3]) -> combinations_with_replacement[tuple[_T, _T, _T]]: ... |
| 326 |
@overload |
| 327 |
def __new__(cls, iterable: Iterable[_T], r: Literal[4]) -> combinations_with_replacement[tuple[_T, _T, _T, _T]]: ... |
| 328 |
@overload |
| 329 |
def __new__(cls, iterable: Iterable[_T], r: Literal[5]) -> combinations_with_replacement[tuple[_T, _T, _T, _T, _T]]: ... |
| 330 |
@overload |
| 331 |
def __new__(cls, iterable: Iterable[_T], r: int) -> combinations_with_replacement[tuple[_T, ...]]: ... |
| 332 |
def __iter__(self) -> Self: ... |
| 333 |
def __next__(self) -> _T_co: ... |
| 334 |
|
| 335 |
if sys.version_info >= (3, 10): |
| 336 |
@disjoint_base |
| 337 |
class pairwise(Generic[_T_co]): |
| 338 |
def __new__(cls, iterable: Iterable[_T], /) -> pairwise[tuple[_T, _T]]: ... |
| 339 |
def __iter__(self) -> Self: ... |
| 340 |
def __next__(self) -> _T_co: ... |
| 341 |
|
| 342 |
if sys.version_info >= (3, 12): |
| 343 |
@disjoint_base |
| 344 |
class batched(Generic[_T_co]): |
| 345 |
if sys.version_info >= (3, 13): |
| 346 |
@overload |
| 347 |
def __new__(cls, iterable: Iterable[_T], n: Literal[1], *, strict: Literal[True]) -> batched[tuple[_T]]: ... |
| 348 |
@overload |
| 349 |
def __new__(cls, iterable: Iterable[_T], n: Literal[2], *, strict: Literal[True]) -> batched[tuple[_T, _T]]: ... |
| 350 |
@overload |
| 351 |
def __new__(cls, iterable: Iterable[_T], n: Literal[3], *, strict: Literal[True]) -> batched[tuple[_T, _T, _T]]: ... |
| 352 |
@overload |
| 353 |
def __new__( |
| 354 |
cls, iterable: Iterable[_T], n: Literal[4], *, strict: Literal[True] |
| 355 |
) -> batched[tuple[_T, _T, _T, _T]]: ... |
| 356 |
@overload |
| 357 |
def __new__( |
| 358 |
cls, iterable: Iterable[_T], n: Literal[5], *, strict: Literal[True] |
| 359 |
) -> batched[tuple[_T, _T, _T, _T, _T]]: ... |
| 360 |
@overload |
| 361 |
def __new__(cls, iterable: Iterable[_T], n: int, *, strict: bool = False) -> batched[tuple[_T, ...]]: ... |
| 362 |
else: |
| 363 |
def __new__(cls, iterable: Iterable[_T], n: int) -> batched[tuple[_T, ...]]: ... |
| 364 |
|
| 365 |
def __iter__(self) -> Self: ... |
| 366 |
def __next__(self) -> _T_co: ... |