Skip to content

Commit

Permalink
Merge pull request #378 from ilai-deutel/update-typing
Browse files Browse the repository at this point in the history
Update and fix typing
  • Loading branch information
bbayles committed Jan 26, 2020
2 parents 4a7444f + 221b40d commit 04f8a12
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
51 changes: 41 additions & 10 deletions more_itertools/more.pyi
Expand Up @@ -6,6 +6,7 @@ from typing import (
Container,
Dict,
Generic,
Hashable,
Iterable,
Iterator,
List,
Expand Down Expand Up @@ -43,11 +44,12 @@ def first(iterable: Iterable[_T], default: _U) -> Union[_T, _U]: ...
def last(iterable: Iterable[_T]) -> _T: ...
@overload
def last(iterable: Iterable[_T], default: _U) -> Union[_T, _U]: ...

@overload
def nth_or_last(iterable: Iterable[_T], n: int) -> _T: ...
@overload
def nth_or_last(iterable: Iterable[_T], n: int, default: _U) -> Union[_T, _U]: ...
def nth_or_last(
iterable: Iterable[_T], n: int, default: _U
) -> Union[_T, _U]: ...

class peekable(Generic[_T], Iterator[_T]):
def __init__(self, iterable: Iterable[_T]) -> None: ...
Expand All @@ -69,15 +71,15 @@ def consumer(func: _GenFn) -> _GenFn: ...
def ilen(iterable: Iterable[object]) -> int: ...
def iterate(func: Callable[[_T], _T], start: _T) -> Iterator[_T]: ...
def with_iter(
context_manager: ContextManager[Iterable[_T]]
context_manager: ContextManager[Iterable[_T]],
) -> Iterator[_T]: ...
def one(
iterable: Iterable[_T],
too_short: Optional[_Raisable] = ...,
too_long: Optional[_Raisable] = ...,
) -> _T: ...
def distinct_permutations(
iterable: Iterable[_T]
iterable: Iterable[_T],
) -> Iterator[Tuple[_T, ...]]: ...
def intersperse(
e: _U, iterable: Iterable[_T], n: int = ...
Expand All @@ -104,6 +106,7 @@ class bucket(Generic[_T, _U], Container[_U]):
validator: Optional[Callable[[object], object]] = ...,
) -> None: ...
def __contains__(self, value: object) -> bool: ...
def __iter__(self) -> Iterator[_U]: ...
def __getitem__(self, value: object) -> Iterator[_T]: ...

def spy(
Expand Down Expand Up @@ -165,7 +168,9 @@ def padded(
@overload
def repeat_last(iterable: Iterable[_T]) -> Iterator[_T]: ...
@overload
def repeat_last(iterable: Iterable[_T], default: _U) -> Iterator[Union[_T, _U]]: ...
def repeat_last(
iterable: Iterable[_T], default: _U
) -> Iterator[Union[_T, _U]]: ...
def distribute(n: int, iterable: Iterable[_T]) -> List[Iterator[_T]]: ...
@overload
def stagger(
Expand Down Expand Up @@ -199,7 +204,10 @@ def sort_together(
def unzip(iterable: Iterable[Sequence[_T]]) -> Tuple[Iterator[_T], ...]: ...
def divide(n: int, iterable: Iterable[_T]) -> List[Iterator[_T]]: ...
def always_iterable(
obj: object, base_type: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...], None] = ...
obj: object,
base_type: Union[
type, Tuple[Union[type, Tuple[Any, ...]], ...], None
] = ...,
) -> Iterator[Any]: ...
def adjacent(
predicate: Callable[[_T], bool],
Expand All @@ -226,7 +234,32 @@ def groupby_transform(
keyfunc: Callable[[_T], _U],
valuefunc: Callable[[_T], _V],
) -> Iterator[Tuple[_U, Iterator[_V]]]: ...
def numeric_range(*args: Any) -> Iterator[Any]: ...

class numeric_range(Generic[_T, _U], Sequence[_T], Hashable, Reversible[_T]):
@overload
def __init__(self, __stop: _T) -> None: ...
@overload
def __init__(self, __start: _T, __stop: _T) -> None: ...
@overload
def __init__(self, __start: _T, __stop: _T, __step: _U) -> None: ...
def __bool__(self) -> bool: ...
def __contains__(self, elem: object) -> bool: ...
def __eq__(self, other: object) -> bool: ...
@overload
def __getitem__(self, key: int) -> _T: ...
@overload
def __getitem__(self, key: slice) -> numeric_range[_T, _U]: ...
def __hash__(self) -> int: ...
def __iter__(self) -> Iterator[_T]: ...
def __len__(self) -> int: ...
def __reduce__(
self,
) -> Tuple[Type[numeric_range[_T, _U]], Tuple[_T, _T, _U]]: ...
def __repr__(self) -> str: ...
def __reversed__(self) -> Iterator[_T]: ...
def count(self, value: _T) -> int: ...
def index(self, value: _T) -> int: ... # type: ignore

def count_cycle(
iterable: Iterable[_T], n: Optional[int] = ...
) -> Iterable[Tuple[int, _T]]: ...
Expand Down Expand Up @@ -363,7 +396,5 @@ def map_except(
*exceptions: Type[BaseException]
) -> Iterator[_U]: ...
def sample(
iterable: Iterable[_T],
k: int,
weights: Optional[Iterable[_T]],
iterable: Iterable[_T], k: int, weights: Optional[Iterable[float]] = ...,
) -> List[_T]: ...
12 changes: 7 additions & 5 deletions more_itertools/recipes.pyi
Expand Up @@ -40,22 +40,24 @@ def repeatfunc(
) -> Iterator[_U]: ...
def pairwise(iterable: Iterable[_T]) -> Iterator[Tuple[_T, _T]]: ...
@overload
def grouper(iterable: Iterable[_T], n: int) -> Iterator[Optional[_T]]: ...
def grouper(
iterable: Iterable[_T], n: int
) -> Iterator[Tuple[Optional[_T], ...]]: ...
@overload
def grouper(
iterable: Iterable[_T], n: int, fillvalue: _U
) -> Iterator[Union[_T, _U]]: ...
) -> Iterator[Tuple[Union[_T, _U], ...]]: ...
@overload
def grouper( # Deprecated interface
iterable: int, n: Iterable[_T]
) -> Iterator[Optional[_T]]: ...
) -> Iterator[Tuple[Optional[_T], ...]]: ...
@overload
def grouper( # Deprecated interface
iterable: int, n: Iterable[_T], fillvalue: _U
) -> Iterator[Union[_T, _U]]: ...
) -> Iterator[Tuple[Union[_T, _U], ...]]: ...
def roundrobin(*iterables: Iterable[_T]) -> Iterator[_T]: ...
def partition(
pred: Callable[[_T], object], iterable: Iterable[_T]
pred: Optional[Callable[[_T], object]], iterable: Iterable[_T]
) -> Tuple[Iterator[_T], Iterator[_T]]: ...
def powerset(iterable: Iterable[_T]) -> Iterator[Tuple[_T, ...]]: ...
def unique_everseen(
Expand Down

0 comments on commit 04f8a12

Please sign in to comment.