Skip to content

Commit 3ba926c

Browse files
committed
Merge pull request #358 from mvcisback/itertools
Restrict types for stubs in itertools
2 parents 85ab2e0 + 6e7885b commit 3ba926c

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

stubs/3.2/itertools.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
# Based on http://docs.python.org/3.2/library/itertools.html
44

5-
from typing import Iterator, typevar, Iterable, overload, Any, Function, Tuple
5+
from typing import (Iterator, typevar, Iterable, overload, Any, Function, Tuple,
6+
Union, Sequence)
67

78
T = typevar('T')
89
S = typevar('S')
@@ -41,11 +42,16 @@ def starmap(func: Any, iterable: Iterable[Any]) -> Iterator[Any]: pass
4142
def takewhile(predicate: Function[[T], Any],
4243
iterable: Iterable[T]) -> Iterator[T]: pass
4344
def tee(iterable: Iterable[Any], n: int = 2) -> Iterator[Any]: pass
44-
def zip_longest(*p: Iterable[Any]) -> Iterator[Any]: pass # TODO fillvalue
45-
46-
def product(*p: Iterable[Any]) -> Iterator[Any]: pass # TODO repeat
47-
# TODO int with None default
48-
def permutations(iterable: Iterable[Any], r: int = None) -> Iterator[Any]: pass
49-
def combinations(iterable: Iterable[Any], r: int) -> Iterable[Any]: pass
50-
def combinations_with_replacement(iterable: Iterable[Any],
51-
r: int) -> Iterable[Any]: pass
45+
def zip_longest(*p: Iterable[Any],
46+
fillvalue: Any = None) -> Iterator[Any]: pass
47+
48+
# TODO: Return type should be Iterator[Tuple[..]], but unknown tuple shape.
49+
# Iterator[Sequence[T]] loses this type information.
50+
def product(*p: Iterable[T], repeat: int = 1) -> Iterator[Sequence[T]]: pass
51+
52+
def permutations(iterable: Iterable[T],
53+
r: Union[int, None] = None) -> Iterator[Sequence[T]]: pass
54+
def combinations(iterable: Iterable[T],
55+
r: int) -> Iterable[Sequence[T]]: pass
56+
def combinations_with_replacement(iterable: Iterable[T],
57+
r: int) -> Iterable[Sequence[T]]: pass

0 commit comments

Comments
 (0)