more.pyi 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. """Stubs for more_itertools.more"""
  2. from __future__ import annotations
  3. import sys
  4. from types import TracebackType
  5. from typing import (
  6. Any,
  7. Callable,
  8. Container,
  9. ContextManager,
  10. Generic,
  11. Hashable,
  12. Mapping,
  13. Iterable,
  14. Iterator,
  15. Mapping,
  16. overload,
  17. Reversible,
  18. Sequence,
  19. Sized,
  20. Type,
  21. TypeVar,
  22. type_check_only,
  23. )
  24. from typing_extensions import Protocol
  25. # Type and type variable definitions
  26. _T = TypeVar('_T')
  27. _T1 = TypeVar('_T1')
  28. _T2 = TypeVar('_T2')
  29. _T3 = TypeVar('_T3')
  30. _T4 = TypeVar('_T4')
  31. _T5 = TypeVar('_T5')
  32. _U = TypeVar('_U')
  33. _V = TypeVar('_V')
  34. _W = TypeVar('_W')
  35. _T_co = TypeVar('_T_co', covariant=True)
  36. _GenFn = TypeVar('_GenFn', bound=Callable[..., Iterator[Any]])
  37. _Raisable = BaseException | Type[BaseException]
  38. # The type of isinstance's second argument (from typeshed builtins)
  39. if sys.version_info >= (3, 10):
  40. _ClassInfo = type | UnionType | tuple[_ClassInfo, ...]
  41. else:
  42. _ClassInfo = type | tuple[_ClassInfo, ...]
  43. @type_check_only
  44. class _SizedIterable(Protocol[_T_co], Sized, Iterable[_T_co]): ...
  45. @type_check_only
  46. class _SizedReversible(Protocol[_T_co], Sized, Reversible[_T_co]): ...
  47. @type_check_only
  48. class _SupportsSlicing(Protocol[_T_co]):
  49. def __getitem__(self, __k: slice) -> _T_co: ...
  50. def chunked(
  51. iterable: Iterable[_T], n: int | None, strict: bool = ...
  52. ) -> Iterator[list[_T]]: ...
  53. @overload
  54. def first(iterable: Iterable[_T]) -> _T: ...
  55. @overload
  56. def first(iterable: Iterable[_T], default: _U) -> _T | _U: ...
  57. @overload
  58. def last(iterable: Iterable[_T]) -> _T: ...
  59. @overload
  60. def last(iterable: Iterable[_T], default: _U) -> _T | _U: ...
  61. @overload
  62. def nth_or_last(iterable: Iterable[_T], n: int) -> _T: ...
  63. @overload
  64. def nth_or_last(iterable: Iterable[_T], n: int, default: _U) -> _T | _U: ...
  65. class peekable(Generic[_T], Iterator[_T]):
  66. def __init__(self, iterable: Iterable[_T]) -> None: ...
  67. def __iter__(self) -> peekable[_T]: ...
  68. def __bool__(self) -> bool: ...
  69. @overload
  70. def peek(self) -> _T: ...
  71. @overload
  72. def peek(self, default: _U) -> _T | _U: ...
  73. def prepend(self, *items: _T) -> None: ...
  74. def __next__(self) -> _T: ...
  75. @overload
  76. def __getitem__(self, index: int) -> _T: ...
  77. @overload
  78. def __getitem__(self, index: slice) -> list[_T]: ...
  79. def consumer(func: _GenFn) -> _GenFn: ...
  80. def ilen(iterable: Iterable[_T]) -> int: ...
  81. def iterate(func: Callable[[_T], _T], start: _T) -> Iterator[_T]: ...
  82. def with_iter(
  83. context_manager: ContextManager[Iterable[_T]],
  84. ) -> Iterator[_T]: ...
  85. def one(
  86. iterable: Iterable[_T],
  87. too_short: _Raisable | None = ...,
  88. too_long: _Raisable | None = ...,
  89. ) -> _T: ...
  90. def raise_(exception: _Raisable, *args: Any) -> None: ...
  91. def strictly_n(
  92. iterable: Iterable[_T],
  93. n: int,
  94. too_short: _GenFn | None = ...,
  95. too_long: _GenFn | None = ...,
  96. ) -> list[_T]: ...
  97. def distinct_permutations(
  98. iterable: Iterable[_T], r: int | None = ...
  99. ) -> Iterator[tuple[_T, ...]]: ...
  100. def intersperse(
  101. e: _U, iterable: Iterable[_T], n: int = ...
  102. ) -> Iterator[_T | _U]: ...
  103. def unique_to_each(*iterables: Iterable[_T]) -> list[list[_T]]: ...
  104. @overload
  105. def windowed(
  106. seq: Iterable[_T], n: int, *, step: int = ...
  107. ) -> Iterator[tuple[_T | None, ...]]: ...
  108. @overload
  109. def windowed(
  110. seq: Iterable[_T], n: int, fillvalue: _U, step: int = ...
  111. ) -> Iterator[tuple[_T | _U, ...]]: ...
  112. def substrings(iterable: Iterable[_T]) -> Iterator[tuple[_T, ...]]: ...
  113. def substrings_indexes(
  114. seq: Sequence[_T], reverse: bool = ...
  115. ) -> Iterator[tuple[Sequence[_T], int, int]]: ...
  116. class bucket(Generic[_T, _U], Container[_U]):
  117. def __init__(
  118. self,
  119. iterable: Iterable[_T],
  120. key: Callable[[_T], _U],
  121. validator: Callable[[_U], object] | None = ...,
  122. ) -> None: ...
  123. def __contains__(self, value: object) -> bool: ...
  124. def __iter__(self) -> Iterator[_U]: ...
  125. def __getitem__(self, value: object) -> Iterator[_T]: ...
  126. def spy(
  127. iterable: Iterable[_T], n: int = ...
  128. ) -> tuple[list[_T], Iterator[_T]]: ...
  129. def interleave(*iterables: Iterable[_T]) -> Iterator[_T]: ...
  130. def interleave_longest(*iterables: Iterable[_T]) -> Iterator[_T]: ...
  131. def interleave_evenly(
  132. iterables: list[Iterable[_T]], lengths: list[int] | None = ...
  133. ) -> Iterator[_T]: ...
  134. def collapse(
  135. iterable: Iterable[Any],
  136. base_type: _ClassInfo | None = ...,
  137. levels: int | None = ...,
  138. ) -> Iterator[Any]: ...
  139. @overload
  140. def side_effect(
  141. func: Callable[[_T], object],
  142. iterable: Iterable[_T],
  143. chunk_size: None = ...,
  144. before: Callable[[], object] | None = ...,
  145. after: Callable[[], object] | None = ...,
  146. ) -> Iterator[_T]: ...
  147. @overload
  148. def side_effect(
  149. func: Callable[[list[_T]], object],
  150. iterable: Iterable[_T],
  151. chunk_size: int,
  152. before: Callable[[], object] | None = ...,
  153. after: Callable[[], object] | None = ...,
  154. ) -> Iterator[_T]: ...
  155. def sliced(
  156. seq: _SupportsSlicing[_T], n: int, strict: bool = ...
  157. ) -> Iterator[_T]: ...
  158. def split_at(
  159. iterable: Iterable[_T],
  160. pred: Callable[[_T], object],
  161. maxsplit: int = ...,
  162. keep_separator: bool = ...,
  163. ) -> Iterator[list[_T]]: ...
  164. def split_before(
  165. iterable: Iterable[_T], pred: Callable[[_T], object], maxsplit: int = ...
  166. ) -> Iterator[list[_T]]: ...
  167. def split_after(
  168. iterable: Iterable[_T], pred: Callable[[_T], object], maxsplit: int = ...
  169. ) -> Iterator[list[_T]]: ...
  170. def split_when(
  171. iterable: Iterable[_T],
  172. pred: Callable[[_T, _T], object],
  173. maxsplit: int = ...,
  174. ) -> Iterator[list[_T]]: ...
  175. def split_into(
  176. iterable: Iterable[_T], sizes: Iterable[int | None]
  177. ) -> Iterator[list[_T]]: ...
  178. @overload
  179. def padded(
  180. iterable: Iterable[_T],
  181. *,
  182. n: int | None = ...,
  183. next_multiple: bool = ...,
  184. ) -> Iterator[_T | None]: ...
  185. @overload
  186. def padded(
  187. iterable: Iterable[_T],
  188. fillvalue: _U,
  189. n: int | None = ...,
  190. next_multiple: bool = ...,
  191. ) -> Iterator[_T | _U]: ...
  192. @overload
  193. def repeat_last(iterable: Iterable[_T]) -> Iterator[_T]: ...
  194. @overload
  195. def repeat_last(iterable: Iterable[_T], default: _U) -> Iterator[_T | _U]: ...
  196. def distribute(n: int, iterable: Iterable[_T]) -> list[Iterator[_T]]: ...
  197. @overload
  198. def stagger(
  199. iterable: Iterable[_T],
  200. offsets: _SizedIterable[int] = ...,
  201. longest: bool = ...,
  202. ) -> Iterator[tuple[_T | None, ...]]: ...
  203. @overload
  204. def stagger(
  205. iterable: Iterable[_T],
  206. offsets: _SizedIterable[int] = ...,
  207. longest: bool = ...,
  208. fillvalue: _U = ...,
  209. ) -> Iterator[tuple[_T | _U, ...]]: ...
  210. class UnequalIterablesError(ValueError):
  211. def __init__(self, details: tuple[int, int, int] | None = ...) -> None: ...
  212. # zip_equal
  213. @overload
  214. def zip_equal(__iter1: Iterable[_T1]) -> Iterator[tuple[_T1]]: ...
  215. @overload
  216. def zip_equal(
  217. __iter1: Iterable[_T1], __iter2: Iterable[_T2]
  218. ) -> Iterator[tuple[_T1, _T2]]: ...
  219. @overload
  220. def zip_equal(
  221. __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3]
  222. ) -> Iterator[tuple[_T1, _T2, _T3]]: ...
  223. @overload
  224. def zip_equal(
  225. __iter1: Iterable[_T1],
  226. __iter2: Iterable[_T2],
  227. __iter3: Iterable[_T3],
  228. __iter4: Iterable[_T4],
  229. ) -> Iterator[tuple[_T1, _T2, _T3, _T4]]: ...
  230. @overload
  231. def zip_equal(
  232. __iter1: Iterable[_T1],
  233. __iter2: Iterable[_T2],
  234. __iter3: Iterable[_T3],
  235. __iter4: Iterable[_T4],
  236. __iter5: Iterable[_T5],
  237. ) -> Iterator[tuple[_T1, _T2, _T3, _T4, _T5]]: ...
  238. @overload
  239. def zip_equal(
  240. __iter1: Iterable[Any],
  241. __iter2: Iterable[Any],
  242. __iter3: Iterable[Any],
  243. __iter4: Iterable[Any],
  244. __iter5: Iterable[Any],
  245. __iter6: Iterable[Any],
  246. *iterables: Iterable[Any],
  247. ) -> Iterator[tuple[Any, ...]]: ...
  248. # zip_offset
  249. @overload
  250. def zip_offset(
  251. __iter1: Iterable[_T1],
  252. *,
  253. offsets: _SizedIterable[int],
  254. longest: bool = ...,
  255. fillvalue: None = None,
  256. ) -> Iterator[tuple[_T1 | None]]: ...
  257. @overload
  258. def zip_offset(
  259. __iter1: Iterable[_T1],
  260. __iter2: Iterable[_T2],
  261. *,
  262. offsets: _SizedIterable[int],
  263. longest: bool = ...,
  264. fillvalue: None = None,
  265. ) -> Iterator[tuple[_T1 | None, _T2 | None]]: ...
  266. @overload
  267. def zip_offset(
  268. __iter1: Iterable[_T],
  269. __iter2: Iterable[_T],
  270. __iter3: Iterable[_T],
  271. *iterables: Iterable[_T],
  272. offsets: _SizedIterable[int],
  273. longest: bool = ...,
  274. fillvalue: None = None,
  275. ) -> Iterator[tuple[_T | None, ...]]: ...
  276. @overload
  277. def zip_offset(
  278. __iter1: Iterable[_T1],
  279. *,
  280. offsets: _SizedIterable[int],
  281. longest: bool = ...,
  282. fillvalue: _U,
  283. ) -> Iterator[tuple[_T1 | _U]]: ...
  284. @overload
  285. def zip_offset(
  286. __iter1: Iterable[_T1],
  287. __iter2: Iterable[_T2],
  288. *,
  289. offsets: _SizedIterable[int],
  290. longest: bool = ...,
  291. fillvalue: _U,
  292. ) -> Iterator[tuple[_T1 | _U, _T2 | _U]]: ...
  293. @overload
  294. def zip_offset(
  295. __iter1: Iterable[_T],
  296. __iter2: Iterable[_T],
  297. __iter3: Iterable[_T],
  298. *iterables: Iterable[_T],
  299. offsets: _SizedIterable[int],
  300. longest: bool = ...,
  301. fillvalue: _U,
  302. ) -> Iterator[tuple[_T | _U, ...]]: ...
  303. def sort_together(
  304. iterables: Iterable[Iterable[_T]],
  305. key_list: Iterable[int] = ...,
  306. key: Callable[..., Any] | None = ...,
  307. reverse: bool = ...,
  308. strict: bool = ...,
  309. ) -> list[tuple[_T, ...]]: ...
  310. def unzip(iterable: Iterable[Sequence[_T]]) -> tuple[Iterator[_T], ...]: ...
  311. def divide(n: int, iterable: Iterable[_T]) -> list[Iterator[_T]]: ...
  312. def always_iterable(
  313. obj: object,
  314. base_type: _ClassInfo | None = ...,
  315. ) -> Iterator[Any]: ...
  316. def adjacent(
  317. predicate: Callable[[_T], bool],
  318. iterable: Iterable[_T],
  319. distance: int = ...,
  320. ) -> Iterator[tuple[bool, _T]]: ...
  321. @overload
  322. def groupby_transform(
  323. iterable: Iterable[_T],
  324. keyfunc: None = None,
  325. valuefunc: None = None,
  326. reducefunc: None = None,
  327. ) -> Iterator[tuple[_T, Iterator[_T]]]: ...
  328. @overload
  329. def groupby_transform(
  330. iterable: Iterable[_T],
  331. keyfunc: Callable[[_T], _U],
  332. valuefunc: None,
  333. reducefunc: None,
  334. ) -> Iterator[tuple[_U, Iterator[_T]]]: ...
  335. @overload
  336. def groupby_transform(
  337. iterable: Iterable[_T],
  338. keyfunc: None,
  339. valuefunc: Callable[[_T], _V],
  340. reducefunc: None,
  341. ) -> Iterable[tuple[_T, Iterable[_V]]]: ...
  342. @overload
  343. def groupby_transform(
  344. iterable: Iterable[_T],
  345. keyfunc: Callable[[_T], _U],
  346. valuefunc: Callable[[_T], _V],
  347. reducefunc: None,
  348. ) -> Iterable[tuple[_U, Iterator[_V]]]: ...
  349. @overload
  350. def groupby_transform(
  351. iterable: Iterable[_T],
  352. keyfunc: None,
  353. valuefunc: None,
  354. reducefunc: Callable[[Iterator[_T]], _W],
  355. ) -> Iterable[tuple[_T, _W]]: ...
  356. @overload
  357. def groupby_transform(
  358. iterable: Iterable[_T],
  359. keyfunc: Callable[[_T], _U],
  360. valuefunc: None,
  361. reducefunc: Callable[[Iterator[_T]], _W],
  362. ) -> Iterable[tuple[_U, _W]]: ...
  363. @overload
  364. def groupby_transform(
  365. iterable: Iterable[_T],
  366. keyfunc: None,
  367. valuefunc: Callable[[_T], _V],
  368. reducefunc: Callable[[Iterable[_V]], _W],
  369. ) -> Iterable[tuple[_T, _W]]: ...
  370. @overload
  371. def groupby_transform(
  372. iterable: Iterable[_T],
  373. keyfunc: Callable[[_T], _U],
  374. valuefunc: Callable[[_T], _V],
  375. reducefunc: Callable[[Iterable[_V]], _W],
  376. ) -> Iterable[tuple[_U, _W]]: ...
  377. class numeric_range(Generic[_T, _U], Sequence[_T], Hashable, Reversible[_T]):
  378. @overload
  379. def __init__(self, __stop: _T) -> None: ...
  380. @overload
  381. def __init__(self, __start: _T, __stop: _T) -> None: ...
  382. @overload
  383. def __init__(self, __start: _T, __stop: _T, __step: _U) -> None: ...
  384. def __bool__(self) -> bool: ...
  385. def __contains__(self, elem: object) -> bool: ...
  386. def __eq__(self, other: object) -> bool: ...
  387. @overload
  388. def __getitem__(self, key: int) -> _T: ...
  389. @overload
  390. def __getitem__(self, key: slice) -> numeric_range[_T, _U]: ...
  391. def __hash__(self) -> int: ...
  392. def __iter__(self) -> Iterator[_T]: ...
  393. def __len__(self) -> int: ...
  394. def __reduce__(
  395. self,
  396. ) -> tuple[Type[numeric_range[_T, _U]], tuple[_T, _T, _U]]: ...
  397. def __repr__(self) -> str: ...
  398. def __reversed__(self) -> Iterator[_T]: ...
  399. def count(self, value: _T) -> int: ...
  400. def index(self, value: _T) -> int: ... # type: ignore
  401. def count_cycle(
  402. iterable: Iterable[_T], n: int | None = ...
  403. ) -> Iterable[tuple[int, _T]]: ...
  404. def mark_ends(
  405. iterable: Iterable[_T],
  406. ) -> Iterable[tuple[bool, bool, _T]]: ...
  407. def locate(
  408. iterable: Iterable[_T],
  409. pred: Callable[..., Any] = ...,
  410. window_size: int | None = ...,
  411. ) -> Iterator[int]: ...
  412. def lstrip(
  413. iterable: Iterable[_T], pred: Callable[[_T], object]
  414. ) -> Iterator[_T]: ...
  415. def rstrip(
  416. iterable: Iterable[_T], pred: Callable[[_T], object]
  417. ) -> Iterator[_T]: ...
  418. def strip(
  419. iterable: Iterable[_T], pred: Callable[[_T], object]
  420. ) -> Iterator[_T]: ...
  421. class islice_extended(Generic[_T], Iterator[_T]):
  422. def __init__(self, iterable: Iterable[_T], *args: int | None) -> None: ...
  423. def __iter__(self) -> islice_extended[_T]: ...
  424. def __next__(self) -> _T: ...
  425. def __getitem__(self, index: slice) -> islice_extended[_T]: ...
  426. def always_reversible(iterable: Iterable[_T]) -> Iterator[_T]: ...
  427. def consecutive_groups(
  428. iterable: Iterable[_T], ordering: Callable[[_T], int] = ...
  429. ) -> Iterator[Iterator[_T]]: ...
  430. @overload
  431. def difference(
  432. iterable: Iterable[_T],
  433. func: Callable[[_T, _T], _U] = ...,
  434. *,
  435. initial: None = ...,
  436. ) -> Iterator[_T | _U]: ...
  437. @overload
  438. def difference(
  439. iterable: Iterable[_T], func: Callable[[_T, _T], _U] = ..., *, initial: _U
  440. ) -> Iterator[_U]: ...
  441. class SequenceView(Generic[_T], Sequence[_T]):
  442. def __init__(self, target: Sequence[_T]) -> None: ...
  443. @overload
  444. def __getitem__(self, index: int) -> _T: ...
  445. @overload
  446. def __getitem__(self, index: slice) -> Sequence[_T]: ...
  447. def __len__(self) -> int: ...
  448. class seekable(Generic[_T], Iterator[_T]):
  449. def __init__(
  450. self, iterable: Iterable[_T], maxlen: int | None = ...
  451. ) -> None: ...
  452. def __iter__(self) -> seekable[_T]: ...
  453. def __next__(self) -> _T: ...
  454. def __bool__(self) -> bool: ...
  455. @overload
  456. def peek(self) -> _T: ...
  457. @overload
  458. def peek(self, default: _U) -> _T | _U: ...
  459. def elements(self) -> SequenceView[_T]: ...
  460. def seek(self, index: int) -> None: ...
  461. def relative_seek(self, count: int) -> None: ...
  462. class run_length:
  463. @staticmethod
  464. def encode(iterable: Iterable[_T]) -> Iterator[tuple[_T, int]]: ...
  465. @staticmethod
  466. def decode(iterable: Iterable[tuple[_T, int]]) -> Iterator[_T]: ...
  467. def exactly_n(
  468. iterable: Iterable[_T], n: int, predicate: Callable[[_T], object] = ...
  469. ) -> bool: ...
  470. def circular_shifts(
  471. iterable: Iterable[_T], steps: int = 1
  472. ) -> list[tuple[_T, ...]]: ...
  473. def make_decorator(
  474. wrapping_func: Callable[..., _U], result_index: int = ...
  475. ) -> Callable[..., Callable[[Callable[..., Any]], Callable[..., _U]]]: ...
  476. @overload
  477. def map_reduce(
  478. iterable: Iterable[_T],
  479. keyfunc: Callable[[_T], _U],
  480. valuefunc: None = ...,
  481. reducefunc: None = ...,
  482. ) -> dict[_U, list[_T]]: ...
  483. @overload
  484. def map_reduce(
  485. iterable: Iterable[_T],
  486. keyfunc: Callable[[_T], _U],
  487. valuefunc: Callable[[_T], _V],
  488. reducefunc: None = ...,
  489. ) -> dict[_U, list[_V]]: ...
  490. @overload
  491. def map_reduce(
  492. iterable: Iterable[_T],
  493. keyfunc: Callable[[_T], _U],
  494. valuefunc: None = ...,
  495. reducefunc: Callable[[list[_T]], _W] = ...,
  496. ) -> dict[_U, _W]: ...
  497. @overload
  498. def map_reduce(
  499. iterable: Iterable[_T],
  500. keyfunc: Callable[[_T], _U],
  501. valuefunc: Callable[[_T], _V],
  502. reducefunc: Callable[[list[_V]], _W],
  503. ) -> dict[_U, _W]: ...
  504. def rlocate(
  505. iterable: Iterable[_T],
  506. pred: Callable[..., object] = ...,
  507. window_size: int | None = ...,
  508. ) -> Iterator[int]: ...
  509. def replace(
  510. iterable: Iterable[_T],
  511. pred: Callable[..., object],
  512. substitutes: Iterable[_U],
  513. count: int | None = ...,
  514. window_size: int = ...,
  515. ) -> Iterator[_T | _U]: ...
  516. def partitions(iterable: Iterable[_T]) -> Iterator[list[list[_T]]]: ...
  517. def set_partitions(
  518. iterable: Iterable[_T],
  519. k: int | None = ...,
  520. min_size: int | None = ...,
  521. max_size: int | None = ...,
  522. ) -> Iterator[list[list[_T]]]: ...
  523. class time_limited(Generic[_T], Iterator[_T]):
  524. def __init__(
  525. self, limit_seconds: float, iterable: Iterable[_T]
  526. ) -> None: ...
  527. def __iter__(self) -> islice_extended[_T]: ...
  528. def __next__(self) -> _T: ...
  529. @overload
  530. def only(
  531. iterable: Iterable[_T], *, too_long: _Raisable | None = ...
  532. ) -> _T | None: ...
  533. @overload
  534. def only(
  535. iterable: Iterable[_T], default: _U, too_long: _Raisable | None = ...
  536. ) -> _T | _U: ...
  537. def ichunked(iterable: Iterable[_T], n: int) -> Iterator[Iterator[_T]]: ...
  538. def distinct_combinations(
  539. iterable: Iterable[_T], r: int
  540. ) -> Iterator[tuple[_T, ...]]: ...
  541. def filter_except(
  542. validator: Callable[[Any], object],
  543. iterable: Iterable[_T],
  544. *exceptions: Type[BaseException],
  545. ) -> Iterator[_T]: ...
  546. def map_except(
  547. function: Callable[[Any], _U],
  548. iterable: Iterable[_T],
  549. *exceptions: Type[BaseException],
  550. ) -> Iterator[_U]: ...
  551. def map_if(
  552. iterable: Iterable[Any],
  553. pred: Callable[[Any], bool],
  554. func: Callable[[Any], Any],
  555. func_else: Callable[[Any], Any] | None = ...,
  556. ) -> Iterator[Any]: ...
  557. def _sample_unweighted(
  558. iterator: Iterator[_T], k: int, strict: bool
  559. ) -> list[_T]: ...
  560. def _sample_counted(
  561. population: Iterator[_T], k: int, counts: Iterable[int], strict: bool
  562. ) -> list[_T]: ...
  563. def _sample_weighted(
  564. iterator: Iterator[_T], k: int, weights, strict
  565. ) -> list[_T]: ...
  566. def sample(
  567. iterable: Iterable[_T],
  568. k: int,
  569. weights: Iterable[float] | None = ...,
  570. *,
  571. counts: Iterable[int] | None = ...,
  572. strict: bool = False,
  573. ) -> list[_T]: ...
  574. def is_sorted(
  575. iterable: Iterable[_T],
  576. key: Callable[[_T], _U] | None = ...,
  577. reverse: bool = False,
  578. strict: bool = False,
  579. ) -> bool: ...
  580. class AbortThread(BaseException):
  581. pass
  582. class callback_iter(Generic[_T], Iterator[_T]):
  583. def __init__(
  584. self,
  585. func: Callable[..., Any],
  586. callback_kwd: str = ...,
  587. wait_seconds: float = ...,
  588. ) -> None: ...
  589. def __enter__(self) -> callback_iter[_T]: ...
  590. def __exit__(
  591. self,
  592. exc_type: Type[BaseException] | None,
  593. exc_value: BaseException | None,
  594. traceback: TracebackType | None,
  595. ) -> bool | None: ...
  596. def __iter__(self) -> callback_iter[_T]: ...
  597. def __next__(self) -> _T: ...
  598. def _reader(self) -> Iterator[_T]: ...
  599. @property
  600. def done(self) -> bool: ...
  601. @property
  602. def result(self) -> Any: ...
  603. def windowed_complete(
  604. iterable: Iterable[_T], n: int
  605. ) -> Iterator[tuple[tuple[_T, ...], tuple[_T, ...], tuple[_T, ...]]]: ...
  606. def all_unique(
  607. iterable: Iterable[_T], key: Callable[[_T], _U] | None = ...
  608. ) -> bool: ...
  609. def nth_product(index: int, *args: Iterable[_T]) -> tuple[_T, ...]: ...
  610. def nth_combination_with_replacement(
  611. iterable: Iterable[_T], r: int, index: int
  612. ) -> tuple[_T, ...]: ...
  613. def nth_permutation(
  614. iterable: Iterable[_T], r: int, index: int
  615. ) -> tuple[_T, ...]: ...
  616. def value_chain(*args: _T | Iterable[_T]) -> Iterable[_T]: ...
  617. def product_index(element: Iterable[_T], *args: Iterable[_T]) -> int: ...
  618. def combination_index(
  619. element: Iterable[_T], iterable: Iterable[_T]
  620. ) -> int: ...
  621. def combination_with_replacement_index(
  622. element: Iterable[_T], iterable: Iterable[_T]
  623. ) -> int: ...
  624. def permutation_index(
  625. element: Iterable[_T], iterable: Iterable[_T]
  626. ) -> int: ...
  627. def repeat_each(iterable: Iterable[_T], n: int = ...) -> Iterator[_T]: ...
  628. class countable(Generic[_T], Iterator[_T]):
  629. def __init__(self, iterable: Iterable[_T]) -> None: ...
  630. def __iter__(self) -> countable[_T]: ...
  631. def __next__(self) -> _T: ...
  632. items_seen: int
  633. def chunked_even(iterable: Iterable[_T], n: int) -> Iterator[list[_T]]: ...
  634. @overload
  635. def zip_broadcast(
  636. __obj1: _T | Iterable[_T],
  637. *,
  638. scalar_types: _ClassInfo | None = ...,
  639. strict: bool = ...,
  640. ) -> Iterable[tuple[_T, ...]]: ...
  641. @overload
  642. def zip_broadcast(
  643. __obj1: _T | Iterable[_T],
  644. __obj2: _T | Iterable[_T],
  645. *,
  646. scalar_types: _ClassInfo | None = ...,
  647. strict: bool = ...,
  648. ) -> Iterable[tuple[_T, ...]]: ...
  649. @overload
  650. def zip_broadcast(
  651. __obj1: _T | Iterable[_T],
  652. __obj2: _T | Iterable[_T],
  653. __obj3: _T | Iterable[_T],
  654. *,
  655. scalar_types: _ClassInfo | None = ...,
  656. strict: bool = ...,
  657. ) -> Iterable[tuple[_T, ...]]: ...
  658. @overload
  659. def zip_broadcast(
  660. __obj1: _T | Iterable[_T],
  661. __obj2: _T | Iterable[_T],
  662. __obj3: _T | Iterable[_T],
  663. __obj4: _T | Iterable[_T],
  664. *,
  665. scalar_types: _ClassInfo | None = ...,
  666. strict: bool = ...,
  667. ) -> Iterable[tuple[_T, ...]]: ...
  668. @overload
  669. def zip_broadcast(
  670. __obj1: _T | Iterable[_T],
  671. __obj2: _T | Iterable[_T],
  672. __obj3: _T | Iterable[_T],
  673. __obj4: _T | Iterable[_T],
  674. __obj5: _T | Iterable[_T],
  675. *,
  676. scalar_types: _ClassInfo | None = ...,
  677. strict: bool = ...,
  678. ) -> Iterable[tuple[_T, ...]]: ...
  679. @overload
  680. def zip_broadcast(
  681. __obj1: _T | Iterable[_T],
  682. __obj2: _T | Iterable[_T],
  683. __obj3: _T | Iterable[_T],
  684. __obj4: _T | Iterable[_T],
  685. __obj5: _T | Iterable[_T],
  686. __obj6: _T | Iterable[_T],
  687. *objects: _T | Iterable[_T],
  688. scalar_types: _ClassInfo | None = ...,
  689. strict: bool = ...,
  690. ) -> Iterable[tuple[_T, ...]]: ...
  691. def unique_in_window(
  692. iterable: Iterable[_T], n: int, key: Callable[[_T], _U] | None = ...
  693. ) -> Iterator[_T]: ...
  694. def duplicates_everseen(
  695. iterable: Iterable[_T], key: Callable[[_T], _U] | None = ...
  696. ) -> Iterator[_T]: ...
  697. def duplicates_justseen(
  698. iterable: Iterable[_T], key: Callable[[_T], _U] | None = ...
  699. ) -> Iterator[_T]: ...
  700. def classify_unique(
  701. iterable: Iterable[_T], key: Callable[[_T], _U] | None = ...
  702. ) -> Iterator[tuple[_T, bool, bool]]: ...
  703. class _SupportsLessThan(Protocol):
  704. def __lt__(self, __other: Any) -> bool: ...
  705. _SupportsLessThanT = TypeVar("_SupportsLessThanT", bound=_SupportsLessThan)
  706. @overload
  707. def minmax(
  708. iterable_or_value: Iterable[_SupportsLessThanT], *, key: None = None
  709. ) -> tuple[_SupportsLessThanT, _SupportsLessThanT]: ...
  710. @overload
  711. def minmax(
  712. iterable_or_value: Iterable[_T], *, key: Callable[[_T], _SupportsLessThan]
  713. ) -> tuple[_T, _T]: ...
  714. @overload
  715. def minmax(
  716. iterable_or_value: Iterable[_SupportsLessThanT],
  717. *,
  718. key: None = None,
  719. default: _U,
  720. ) -> _U | tuple[_SupportsLessThanT, _SupportsLessThanT]: ...
  721. @overload
  722. def minmax(
  723. iterable_or_value: Iterable[_T],
  724. *,
  725. key: Callable[[_T], _SupportsLessThan],
  726. default: _U,
  727. ) -> _U | tuple[_T, _T]: ...
  728. @overload
  729. def minmax(
  730. iterable_or_value: _SupportsLessThanT,
  731. __other: _SupportsLessThanT,
  732. *others: _SupportsLessThanT,
  733. ) -> tuple[_SupportsLessThanT, _SupportsLessThanT]: ...
  734. @overload
  735. def minmax(
  736. iterable_or_value: _T,
  737. __other: _T,
  738. *others: _T,
  739. key: Callable[[_T], _SupportsLessThan],
  740. ) -> tuple[_T, _T]: ...
  741. def longest_common_prefix(
  742. iterables: Iterable[Iterable[_T]],
  743. ) -> Iterator[_T]: ...
  744. def iequals(*iterables: Iterable[Any]) -> bool: ...
  745. def constrained_batches(
  746. iterable: Iterable[_T],
  747. max_size: int,
  748. max_count: int | None = ...,
  749. get_len: Callable[[_T], object] = ...,
  750. strict: bool = ...,
  751. ) -> Iterator[tuple[_T]]: ...
  752. def gray_product(*iterables: Iterable[_T]) -> Iterator[tuple[_T, ...]]: ...
  753. def partial_product(*iterables: Iterable[_T]) -> Iterator[tuple[_T, ...]]: ...
  754. def takewhile_inclusive(
  755. predicate: Callable[[_T], bool], iterable: Iterable[_T]
  756. ) -> Iterator[_T]: ...
  757. def outer_product(
  758. func: Callable[[_T, _U], _V],
  759. xs: Iterable[_T],
  760. ys: Iterable[_U],
  761. *args: Any,
  762. **kwargs: Any,
  763. ) -> Iterator[tuple[_V, ...]]: ...
  764. def iter_suppress(
  765. iterable: Iterable[_T],
  766. *exceptions: Type[BaseException],
  767. ) -> Iterator[_T]: ...
  768. def filter_map(
  769. func: Callable[[_T], _V | None],
  770. iterable: Iterable[_T],
  771. ) -> Iterator[_V]: ...
  772. def powerset_of_sets(iterable: Iterable[_T]) -> Iterator[set[_T]]: ...
  773. def join_mappings(
  774. **field_to_map: Mapping[_T, _V]
  775. ) -> dict[_T, dict[str, _V]]: ...
  776. def doublestarmap(
  777. func: Callable[..., _T],
  778. iterable: Iterable[Mapping[str, Any]],
  779. ) -> Iterator[_T]: ...
  780. def dft(xarr: Sequence[complex]) -> Iterator[complex]: ...
  781. def idft(Xarr: Sequence[complex]) -> Iterator[complex]: ...