Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,18 @@ def sorted(__iterable: Iterable[_T], *, key: Callable[[_T], SupportsRichComparis
_SumT = TypeVar("_SumT", bound=SupportsAdd)
_SumS = TypeVar("_SumS", bound=SupportsAdd)

# In general, the return type of `x + x` is *not* guaranteed to be the same type as x.
# However, we can't express that in the stub for `sum()`
# without creating many false-positive errors (see #7578).
# Instead, we special-case the most common example of this: bool.
if sys.version_info >= (3, 8):
Comment thread
AlexWaygood marked this conversation as resolved.
@overload
def sum(__iterable: Iterable[bool], start: int = ...) -> int: ... # type: ignore[misc]

else:
@overload
def sum(__iterable: Iterable[bool], __start: int = ...) -> int: ... # type: ignore[misc]

@overload
def sum(__iterable: Iterable[_SumT]) -> _SumT | Literal[0]: ...

Expand Down