From b0c0f942109220ff1af158bc0e21115a34487bb7 Mon Sep 17 00:00:00 2001 From: Sidharth Kapur Date: Sat, 20 Feb 2016 22:31:17 -0600 Subject: [PATCH 1/6] Fix type for reduce --- stdlib/3/functools.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/3/functools.pyi b/stdlib/3/functools.pyi index e8563b5aa..579716b9a 100644 --- a/stdlib/3/functools.pyi +++ b/stdlib/3/functools.pyi @@ -9,8 +9,9 @@ from collections import namedtuple _AnyCallable = Callable[..., Any] _T = TypeVar("_T") -def reduce(function: Callable[[_T], _T], - sequence: Iterator[_T], initial: Optional[_T] = ...) -> _T: ... +_S = TypeVar("_S") +def reduce(function: Callable[[_T, _S], _T], + sequence: Iterator[_S], initial: Optional[_T] = ...) -> _T: ... class CacheInfo(NamedTuple('CacheInfo', [ From fd9310fa97b80c7db6333725f77df109cd715d5a Mon Sep 17 00:00:00 2001 From: Sidharth Kapur Date: Sat, 20 Feb 2016 22:46:39 -0600 Subject: [PATCH 2/6] Overload the reduce function --- stdlib/3/functools.pyi | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stdlib/3/functools.pyi b/stdlib/3/functools.pyi index 579716b9a..76769dcff 100644 --- a/stdlib/3/functools.pyi +++ b/stdlib/3/functools.pyi @@ -10,8 +10,12 @@ _AnyCallable = Callable[..., Any] _T = TypeVar("_T") _S = TypeVar("_S") +@overload def reduce(function: Callable[[_T, _S], _T], - sequence: Iterator[_S], initial: Optional[_T] = ...) -> _T: ... + sequence: Iterator[_S], initial: _T) -> _T: ... +@overload +def reduce(function: Callable[[_T, _T], _T], + sequence: Iterator[_T]) -> _T: ... class CacheInfo(NamedTuple('CacheInfo', [ From dc647c3ed5f46aeed1a7585f7909b6bbc1d79dad Mon Sep 17 00:00:00 2001 From: Sidharth Kapur Date: Sat, 20 Feb 2016 22:49:12 -0600 Subject: [PATCH 3/6] Fix imports --- stdlib/3/functools.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/functools.pyi b/stdlib/3/functools.pyi index 76769dcff..7db91aaf5 100644 --- a/stdlib/3/functools.pyi +++ b/stdlib/3/functools.pyi @@ -3,7 +3,7 @@ # NOTE: These are incomplete! from abc import ABCMeta, abstractmethod -from typing import Any, Callable, Generic, Dict, Iterator, Optional, Sequence, Tuple, TypeVar, NamedTuple +from typing import Any, Callable, Generic, Dict, Iterator, Optional, Sequence, Tuple, TypeVar, NamedTuple, overload from collections import namedtuple _AnyCallable = Callable[..., Any] From 2904b803692a3f52d9a605358e9460aae670b649 Mon Sep 17 00:00:00 2001 From: Sidharth Kapur Date: Mon, 22 Feb 2016 17:27:46 -0600 Subject: [PATCH 4/6] Update type for reduce in stdlib/2.7/functools --- stdlib/2.7/__builtin__.pyi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib/2.7/__builtin__.pyi b/stdlib/2.7/__builtin__.pyi index 546202b29..2c877c285 100644 --- a/stdlib/2.7/__builtin__.pyi +++ b/stdlib/2.7/__builtin__.pyi @@ -714,7 +714,10 @@ def quit(code: int = ...) -> None: ... def range(x: int, y: int = 0, step: int = 1) -> List[int]: ... def raw_input(prompt: unicode = ...) -> str: ... -def reduce(function: Callable[[_T, _T], _T], iterable: Iterable[_T], initializer: _T = None) -> _T: ... +@overload +def reduce(function: Callable[[_T, _S], _T], iterable: Iterable[_S], initializer: _T) -> _T: ... +@overload +def reduce(function: Callable[[_T, _T], _T], iterable: Iterable[_T]) -> _T: ... def reload(module: Any) -> Any: ... @overload From 241e741ef2df65cb7f1c55b09c94409a49f48969 Mon Sep 17 00:00:00 2001 From: Sidharth Kapur Date: Mon, 22 Feb 2016 17:41:47 -0600 Subject: [PATCH 5/6] Change Iterator to Iterable in type of reduce --- stdlib/3/functools.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3/functools.pyi b/stdlib/3/functools.pyi index 7db91aaf5..7c0c0d7bb 100644 --- a/stdlib/3/functools.pyi +++ b/stdlib/3/functools.pyi @@ -12,10 +12,10 @@ _T = TypeVar("_T") _S = TypeVar("_S") @overload def reduce(function: Callable[[_T, _S], _T], - sequence: Iterator[_S], initial: _T) -> _T: ... + sequence: Iterable[_S], initial: _T) -> _T: ... @overload def reduce(function: Callable[[_T, _T], _T], - sequence: Iterator[_T]) -> _T: ... + sequence: Iterable[_T]) -> _T: ... class CacheInfo(NamedTuple('CacheInfo', [ From 8b428ce2ff5094acc030e6e47ec5c096cf571e70 Mon Sep 17 00:00:00 2001 From: Sidharth Kapur Date: Mon, 22 Feb 2016 17:44:07 -0600 Subject: [PATCH 6/6] Fix imports --- stdlib/3/functools.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/functools.pyi b/stdlib/3/functools.pyi index 7c0c0d7bb..0982cfebd 100644 --- a/stdlib/3/functools.pyi +++ b/stdlib/3/functools.pyi @@ -3,7 +3,7 @@ # NOTE: These are incomplete! from abc import ABCMeta, abstractmethod -from typing import Any, Callable, Generic, Dict, Iterator, Optional, Sequence, Tuple, TypeVar, NamedTuple, overload +from typing import Any, Callable, Generic, Dict, Iterable, Optional, Sequence, Tuple, TypeVar, NamedTuple, overload from collections import namedtuple _AnyCallable = Callable[..., Any]