mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 05:24:52 +08:00
More precise return type for sum() (#6573)
It returns 0 on an empty iterable, and that's the only int it can return for arbitrary iterables.
This commit is contained in:
@@ -1385,13 +1385,13 @@ def sorted(__iterable: Iterable[_T], *, key: Callable[[_T], SupportsLessThan], r
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
@overload
|
||||
def sum(__iterable: Iterable[_T]) -> _T | int: ...
|
||||
def sum(__iterable: Iterable[_T]) -> _T | Literal[0]: ...
|
||||
@overload
|
||||
def sum(__iterable: Iterable[_T], start: _S) -> _T | _S: ...
|
||||
|
||||
else:
|
||||
@overload
|
||||
def sum(__iterable: Iterable[_T]) -> _T | int: ...
|
||||
def sum(__iterable: Iterable[_T]) -> _T | Literal[0]: ...
|
||||
@overload
|
||||
def sum(__iterable: Iterable[_T], __start: _S) -> _T | _S: ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user