From 355f30cc70ed325c0637b6a32bbbe6dbd371846b Mon Sep 17 00:00:00 2001 From: Travis Parker Date: Wed, 4 Oct 2017 21:42:35 -0700 Subject: [PATCH] Correct return type of sum() builtin (#1582) `sum([])` always returns the integer 0. --- stdlib/2/__builtin__.pyi | 5 ++++- stdlib/3/builtins.pyi | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index b781292ec..0b8dfb1b3 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -789,7 +789,10 @@ def sorted(iterable: Iterable[_T], *, cmp: Callable[[_T, _T], int] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) -> List[_T]: ... -def sum(iterable: Iterable[_T], start: _T = ...) -> _T: ... +@overload +def sum(iterable: Iterable[_T]) -> Union[_T, int]: ... +@overload +def sum(iterable: Iterable[_T], start: _S) -> Union[_T, _S]: ... def unichr(i: int) -> unicode: ... def vars(object: Any = ...) -> Dict[str, Any]: ... @overload diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 8d0dfb883..7780fccc8 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -861,7 +861,10 @@ def setattr(object: Any, name: str, value: Any) -> None: ... def sorted(iterable: Iterable[_T], *, key: Optional[Callable[[_T], Any]] = None, reverse: bool = False) -> List[_T]: ... -def sum(iterable: Iterable[_T], start: _T = ...) -> _T: ... +@overload +def sum(iterable: Iterable[_T]) -> Union[_T, int]: ... +@overload +def sum(iterable: Iterable[_T], start: _S) -> Union[_T, _S]: ... def vars(object: Any = ...) -> Dict[str, Any]: ... @overload def zip(iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]: ...