Format: application/octet-stream
⬇ Download File (4.4 KB)
   1  import sys
   2  from typing import Any, Callable, Generic, Iterable, Iterator, Optional, Tuple, TypeVar, overload
   3  from typing_extensions import Literal
   4  
   5  _T = TypeVar("_T")
   6  _S = TypeVar("_S")
   7  _N = TypeVar("_N", int, float)
   8  Predicate = Callable[[_T], object]
   9  
  10  def count(start: _N = ..., step: _N = ...) -> Iterator[_N]: ...  # more general types?
  11  
  12  class cycle(Iterator[_T], Generic[_T]):
  13      def __init__(self, iterable: Iterable[_T]) -> None: ...
  14      def __next__(self) -> _T: ...
  15      def __iter__(self) -> Iterator[_T]: ...
  16  
  17  @overload
  18  def repeat(object: _T) -> Iterator[_T]: ...
  19  @overload
  20  def repeat(object: _T, times: int) -> Iterator[_T]: ...
  21  
  22  if sys.version_info >= (3, 8):
  23      @overload
  24      def accumulate(iterable: Iterable[_T], func: Callable[[_T, _T], _T] = ...) -> Iterator[_T]: ...
  25      @overload
  26      def accumulate(iterable: Iterable[_T], func: Callable[[_S, _T], _S], initial: Optional[_S]) -> Iterator[_S]: ...
  27  
  28  else:
  29      def accumulate(iterable: Iterable[_T], func: Callable[[_T, _T], _T] = ...) -> Iterator[_T]: ...
  30  
  31  class chain(Iterator[_T], Generic[_T]):
  32      def __init__(self, *iterables: Iterable[_T]) -> None: ...
  33      def __next__(self) -> _T: ...
  34      def __iter__(self) -> Iterator[_T]: ...
  35      @staticmethod
  36      def from_iterable(iterable: Iterable[Iterable[_S]]) -> Iterator[_S]: ...
  37  
  38  def compress(data: Iterable[_T], selectors: Iterable[Any]) -> Iterator[_T]: ...
  39  def dropwhile(predicate: Predicate[_T], iterable: Iterable[_T]) -> Iterator[_T]: ...
  40  def filterfalse(predicate: Optional[Predicate[_T]], iterable: Iterable[_T]) -> Iterator[_T]: ...
  41  @overload
  42  def groupby(iterable: Iterable[_T], key: None = ...) -> Iterator[Tuple[_T, Iterator[_T]]]: ...
  43  @overload
  44  def groupby(iterable: Iterable[_T], key: Callable[[_T], _S]) -> Iterator[Tuple[_S, Iterator[_T]]]: ...
  45  @overload
  46  def islice(iterable: Iterable[_T], stop: Optional[int]) -> Iterator[_T]: ...
  47  @overload
  48  def islice(iterable: Iterable[_T], start: Optional[int], stop: Optional[int], step: Optional[int] = ...) -> Iterator[_T]: ...
  49  def starmap(func: Callable[..., _S], iterable: Iterable[Iterable[Any]]) -> Iterator[_S]: ...
  50  def takewhile(predicate: Predicate[_T], iterable: Iterable[_T]) -> Iterator[_T]: ...
  51  def tee(iterable: Iterable[_T], n: int = ...) -> Tuple[Iterator[_T], ...]: ...
  52  def zip_longest(*p: Iterable[Any], fillvalue: Any = ...) -> Iterator[Any]: ...
  53  
  54  _T1 = TypeVar("_T1")
  55  _T2 = TypeVar("_T2")
  56  _T3 = TypeVar("_T3")
  57  _T4 = TypeVar("_T4")
  58  _T5 = TypeVar("_T5")
  59  _T6 = TypeVar("_T6")
  60  @overload
  61  def product(iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]: ...
  62  @overload
  63  def product(iter1: Iterable[_T1], iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]: ...
  64  @overload
  65  def product(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3]) -> Iterator[Tuple[_T1, _T2, _T3]]: ...
  66  @overload
  67  def product(
  68      iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4]
  69  ) -> Iterator[Tuple[_T1, _T2, _T3, _T4]]: ...
  70  @overload
  71  def product(
  72      iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4], iter5: Iterable[_T5]
  73  ) -> Iterator[Tuple[_T1, _T2, _T3, _T4, _T5]]: ...
  74  @overload
  75  def product(
  76      iter1: Iterable[_T1],
  77      iter2: Iterable[_T2],
  78      iter3: Iterable[_T3],
  79      iter4: Iterable[_T4],
  80      iter5: Iterable[_T5],
  81      iter6: Iterable[_T6],
  82  ) -> Iterator[Tuple[_T1, _T2, _T3, _T4, _T5, _T6]]: ...
  83  @overload
  84  def product(
  85      iter1: Iterable[Any],
  86      iter2: Iterable[Any],
  87      iter3: Iterable[Any],
  88      iter4: Iterable[Any],
  89      iter5: Iterable[Any],
  90      iter6: Iterable[Any],
  91      iter7: Iterable[Any],
  92      *iterables: Iterable[Any],
  93  ) -> Iterator[Tuple[Any, ...]]: ...
  94  @overload
  95  def product(*iterables: Iterable[_T1], repeat: int) -> Iterator[Tuple[_T1, ...]]: ...
  96  @overload
  97  def product(*iterables: Iterable[Any], repeat: int = ...) -> Iterator[Tuple[Any, ...]]: ...
  98  def permutations(iterable: Iterable[_T], r: Optional[int] = ...) -> Iterator[Tuple[_T, ...]]: ...
  99  @overload
 100  def combinations(iterable: Iterable[_T], r: Literal[2]) -> Iterator[Tuple[_T, _T]]: ...
 101  @overload
 102  def combinations(iterable: Iterable[_T], r: Literal[3]) -> Iterator[Tuple[_T, _T, _T]]: ...
 103  @overload
 104  def combinations(iterable: Iterable[_T], r: Literal[4]) -> Iterator[Tuple[_T, _T, _T, _T]]: ...
 105  @overload
 106  def combinations(iterable: Iterable[_T], r: Literal[5]) -> Iterator[Tuple[_T, _T, _T, _T, _T]]: ...
 107  @overload
 108  def combinations(iterable: Iterable[_T], r: int) -> Iterator[Tuple[_T, ...]]: ...
 109  def combinations_with_replacement(iterable: Iterable[_T], r: int) -> Iterator[Tuple[_T, ...]]: ...
 110