From 2d96eecd3008272ea656b031c9fba81f49832580 Mon Sep 17 00:00:00 2001 From: Manuel Krebber Date: Wed, 3 May 2017 17:53:48 +0200 Subject: [PATCH] Itertools update (#1233) * Updated the typehints for itertools. * Removed the overload because it caused problems and cleaned up the imports. * Update itertools.pyi Added back optionality of second argument for itertools.permutations. * Update itertools.pyi Moved the Optional which I accidentially put on the wrong function -.- --- stdlib/3/itertools.pyi | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/stdlib/3/itertools.pyi b/stdlib/3/itertools.pyi index 889d583c5..774d68fb3 100644 --- a/stdlib/3/itertools.pyi +++ b/stdlib/3/itertools.pyi @@ -3,7 +3,7 @@ # Based on http://docs.python.org/3.2/library/itertools.html from typing import (Iterator, TypeVar, Iterable, overload, Any, Callable, Tuple, - Union, Sequence, Generic, Optional) + Generic, Optional) _T = TypeVar('_T') _S = TypeVar('_S') @@ -44,20 +44,18 @@ def islice(iterable: Iterable[_T], stop: int) -> Iterator[_T]: ... def islice(iterable: Iterable[_T], start: int, stop: Optional[int], step: int = ...) -> Iterator[_T]: ... -def starmap(func: Any, iterable: Iterable[Any]) -> Iterator[Any]: ... +def starmap(func: Callable[..., _S], iterable: Iterable[Iterable[Any]]) -> Iterator[_S]: ... def takewhile(predicate: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ... -def tee(iterable: Iterable[Any], n: int = ...) -> Iterator[Any]: ... +def tee(iterable: Iterable[_T], n: int = ...) -> Tuple[Iterator[_T], ...]: ... def zip_longest(*p: Iterable[Any], fillvalue: Any = ...) -> Iterator[Any]: ... -# TODO: Return type should be Iterator[Tuple[..]], but unknown tuple shape. -# Iterator[Sequence[_T]] loses this type information. -def product(*p: Iterable[_T], repeat: int = ...) -> Iterator[Sequence[_T]]: ... +def product(*p: Iterable[_T], repeat: int = ...) -> Iterator[Tuple[_T, ...]]: ... def permutations(iterable: Iterable[_T], - r: Union[int, None] = ...) -> Iterator[Sequence[_T]]: ... + r: Optional[int] = ...) -> Iterator[Tuple[_T, ...]]: ... def combinations(iterable: Iterable[_T], - r: int) -> Iterable[Sequence[_T]]: ... + r: int) -> Iterable[Tuple[_T, ...]]: ... def combinations_with_replacement(iterable: Iterable[_T], - r: int) -> Iterable[Sequence[_T]]: ... + r: int) -> Iterable[Tuple[_T, ...]]: ...