Skip to content

Commit d2469c0

Browse files
JelleZijlstragvanrossum
authored andcommitted
fix type for itertools.product (#2129)
Fixes #1850. The fix was already applied to Python 2, but the typevar-based solution there leads to "cannot infer value of type variable" in mypy. I used the following script to check: ```python from itertools import product reveal_type(product([1])) reveal_type(product([1], ['x'], [False], [3.0], [(1,)], [('x',)], [{1}], [{1: 2}], repeat=5)) ```
1 parent ced5d61 commit d2469c0

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

stdlib/2/itertools.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ def product(iter1: Iterable[Any],
153153
iter4: Iterable[Any],
154154
iter5: Iterable[Any],
155155
iter6: Iterable[Any],
156-
iter7: Iterable[Any], *iterables: Iterable) -> Iterator[Tuple]: ...
156+
iter7: Iterable[Any],
157+
*iterables: Iterable[Any]) -> Iterator[Tuple[Any, ...]]: ...
157158
@overload
158-
def product(*iter: Iterable[_T], repeat: int) -> Iterator[Tuple[_T, ...]]: ...
159+
def product(*iterables: Iterable[Any], repeat: int) -> Iterator[Tuple[Any, ...]]: ...
159160

160161
def permutations(iterable: Iterable[_T],
161162
r: int = ...) -> Iterator[Sequence[_T]]: ...

stdlib/3/itertools.pyi

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,47 +60,43 @@ _T5 = TypeVar('_T5')
6060
_T6 = TypeVar('_T6')
6161

6262
@overload
63-
def product(iter1: Iterable[_T1], *,
64-
repeat: int = ...) -> Iterator[Tuple[_T1]]: ...
63+
def product(iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]: ...
6564
@overload
6665
def product(iter1: Iterable[_T1],
67-
iter2: Iterable[_T2], *,
68-
repeat: int = ...) -> Iterator[Tuple[_T1, _T2]]: ...
66+
iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]: ...
6967
@overload
7068
def product(iter1: Iterable[_T1],
7169
iter2: Iterable[_T2],
72-
iter3: Iterable[_T3], *,
73-
repeat: int = ...) -> Iterator[Tuple[_T1, _T2, _T3]]: ...
70+
iter3: Iterable[_T3]) -> Iterator[Tuple[_T1, _T2, _T3]]: ...
7471
@overload
7572
def product(iter1: Iterable[_T1],
7673
iter2: Iterable[_T2],
7774
iter3: Iterable[_T3],
78-
iter4: Iterable[_T4], *,
79-
repeat: int = ...) -> Iterator[Tuple[_T1, _T2, _T3, _T4]]: ...
75+
iter4: Iterable[_T4]) -> Iterator[Tuple[_T1, _T2, _T3, _T4]]: ...
8076
@overload
8177
def product(iter1: Iterable[_T1],
8278
iter2: Iterable[_T2],
8379
iter3: Iterable[_T3],
8480
iter4: Iterable[_T4],
85-
iter5: Iterable[_T5], *,
86-
repeat: int = ...) -> Iterator[Tuple[_T1, _T2, _T3, _T4, _T5]]: ...
81+
iter5: Iterable[_T5]) -> Iterator[Tuple[_T1, _T2, _T3, _T4, _T5]]: ...
8782
@overload
8883
def product(iter1: Iterable[_T1],
8984
iter2: Iterable[_T2],
9085
iter3: Iterable[_T3],
9186
iter4: Iterable[_T4],
9287
iter5: Iterable[_T5],
93-
iter6: Iterable[_T6], *,
94-
repeat: int = ...) -> Iterator[Tuple[_T1, _T2, _T3, _T4, _T5, _T6]]: ...
88+
iter6: Iterable[_T6]) -> Iterator[Tuple[_T1, _T2, _T3, _T4, _T5, _T6]]: ...
9589
@overload
9690
def product(iter1: Iterable[Any],
9791
iter2: Iterable[Any],
9892
iter3: Iterable[Any],
9993
iter4: Iterable[Any],
10094
iter5: Iterable[Any],
10195
iter6: Iterable[Any],
102-
iter7: Iterable[Any], *iterables: Iterable,
103-
repeat: int = ...) -> Iterator[Tuple]: ...
96+
iter7: Iterable[Any],
97+
*iterables: Iterable[Any]) -> Iterator[Tuple[Any, ...]]: ...
98+
@overload
99+
def product(*iterables: Iterable[Any], repeat: int) -> Iterator[Tuple[Any, ...]]: ...
104100

105101
def permutations(iterable: Iterable[_T],
106102
r: Optional[int] = ...) -> Iterator[Tuple[_T, ...]]: ...

0 commit comments

Comments
 (0)