From 61490b88ba6347349607dae4c96dcc21954faecd Mon Sep 17 00:00:00 2001 From: Marcell Vazquez-Chanlatte Date: Sun, 3 Aug 2014 15:07:58 -0700 Subject: [PATCH 1/4] restricted types of itertools stubs --- stubs/3.2/itertools.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/stubs/3.2/itertools.py b/stubs/3.2/itertools.py index fdedef5f7339..265a44cea447 100644 --- a/stubs/3.2/itertools.py +++ b/stubs/3.2/itertools.py @@ -2,7 +2,8 @@ # Based on http://docs.python.org/3.2/library/itertools.html -from typing import Iterator, typevar, Iterable, overload, Any, Function, Tuple +from typing import (Iterator, typevar, Iterable, overload, Any, Function, Tuple, + Union) T = typevar('T') S = typevar('S') @@ -41,11 +42,14 @@ def starmap(func: Any, iterable: Iterable[Any]) -> Iterator[Any]: pass def takewhile(predicate: Function[[T], Any], iterable: Iterable[T]) -> Iterator[T]: pass def tee(iterable: Iterable[Any], n: int = 2) -> Iterator[Any]: pass -def zip_longest(*p: Iterable[Any]) -> Iterator[Any]: pass # TODO fillvalue - -def product(*p: Iterable[Any]) -> Iterator[Any]: pass # TODO repeat -# TODO int with None default -def permutations(iterable: Iterable[Any], r: int = None) -> Iterator[Any]: pass -def combinations(iterable: Iterable[Any], r: int) -> Iterable[Any]: pass -def combinations_with_replacement(iterable: Iterable[Any], - r: int) -> Iterable[Any]: pass +def zip_longest(*p: Iterable[Any], + fillvalue: Any = None) -> Iterator[Any]: pass + +def product(*p: Iterable[T], repeat: int = 1) -> Iterator[T]: pass + +def permutations(iterable: Iterable[T], + r: Union[int, None] = None) -> Iterator[Iterator[T]]: pass +def combinations(iterable: Iterable[T], + r: int) -> Iterable[Iterable[T]]: pass +def combinations_with_replacement(iterable: Iterable[T], + r: int) -> Iterable[Iterable[T]]: pass From c22f5970a41451b1f00e8ab4007a127fca4126e7 Mon Sep 17 00:00:00 2001 From: Marcell Vazquez-Chanlatte Date: Sun, 3 Aug 2014 17:16:00 -0700 Subject: [PATCH 2/4] fixed incorrect restrictions --- stubs/3.2/itertools.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stubs/3.2/itertools.py b/stubs/3.2/itertools.py index 265a44cea447..c96276f58b1e 100644 --- a/stubs/3.2/itertools.py +++ b/stubs/3.2/itertools.py @@ -3,7 +3,7 @@ # Based on http://docs.python.org/3.2/library/itertools.html from typing import (Iterator, typevar, Iterable, overload, Any, Function, Tuple, - Union) + Union, Sequence) T = typevar('T') S = typevar('S') @@ -45,11 +45,11 @@ def tee(iterable: Iterable[Any], n: int = 2) -> Iterator[Any]: pass def zip_longest(*p: Iterable[Any], fillvalue: Any = None) -> Iterator[Any]: pass -def product(*p: Iterable[T], repeat: int = 1) -> Iterator[T]: pass +def product(*p: Iterable[Iterable[T]], repeat: int = 1) -> Iterator[T]: pass def permutations(iterable: Iterable[T], - r: Union[int, None] = None) -> Iterator[Iterator[T]]: pass + r: Union[int, None] = None) -> Iterator[Sequence[T]]: pass def combinations(iterable: Iterable[T], - r: int) -> Iterable[Iterable[T]]: pass + r: int) -> Iterable[Sequence[T]]: pass def combinations_with_replacement(iterable: Iterable[T], - r: int) -> Iterable[Iterable[T]]: pass + r: int) -> Iterable[Sequence[T]]: pass From 47879ec8af4ba545c5784195c4131479297855c8 Mon Sep 17 00:00:00 2001 From: Marcell Vazquez-Chanlatte Date: Thu, 7 Aug 2014 13:33:36 -0700 Subject: [PATCH 3/4] fixed output of product to Iterator[Sequence[T]] --- stubs/3.2/itertools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/3.2/itertools.py b/stubs/3.2/itertools.py index c96276f58b1e..b00e0b261919 100644 --- a/stubs/3.2/itertools.py +++ b/stubs/3.2/itertools.py @@ -45,7 +45,7 @@ def tee(iterable: Iterable[Any], n: int = 2) -> Iterator[Any]: pass def zip_longest(*p: Iterable[Any], fillvalue: Any = None) -> Iterator[Any]: pass -def product(*p: Iterable[Iterable[T]], repeat: int = 1) -> Iterator[T]: pass +def product(*p: Iterable[Iterable[T]], repeat: int = 1) -> Iterator[Sequence[T]]: pass def permutations(iterable: Iterable[T], r: Union[int, None] = None) -> Iterator[Sequence[T]]: pass From 6e7885bd47a2080264d1d038793b9285d80d3ed2 Mon Sep 17 00:00:00 2001 From: Marcell Vazquez-Chanlatte Date: Thu, 7 Aug 2014 22:23:13 -0700 Subject: [PATCH 4/4] fixed input type of product, and added note about type sig --- stubs/3.2/itertools.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stubs/3.2/itertools.py b/stubs/3.2/itertools.py index b00e0b261919..0c96de833599 100644 --- a/stubs/3.2/itertools.py +++ b/stubs/3.2/itertools.py @@ -45,7 +45,9 @@ def tee(iterable: Iterable[Any], n: int = 2) -> Iterator[Any]: pass def zip_longest(*p: Iterable[Any], fillvalue: Any = None) -> Iterator[Any]: pass -def product(*p: Iterable[Iterable[T]], repeat: int = 1) -> Iterator[Sequence[T]]: pass +# 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 = 1) -> Iterator[Sequence[T]]: pass def permutations(iterable: Iterable[T], r: Union[int, None] = None) -> Iterator[Sequence[T]]: pass