diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 99783cd60..ce2042bca 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1477,16 +1477,23 @@ def sorted( ) -> list[SupportsRichComparisonT]: ... @overload def sorted(__iterable: Iterable[_T], *, key: Callable[[_T], SupportsRichComparison], reverse: bool = ...) -> list[_T]: ... + +class _SupportsSum(Protocol): + def __add__(self, __x: Any) -> Any: ... + +_SumT = TypeVar("_SumT", bound=_SupportsSum) +_SumS = TypeVar("_SumS", bound=_SupportsSum) + @overload -def sum(__iterable: Iterable[_T]) -> _T | Literal[0]: ... +def sum(__iterable: Iterable[_SumT]) -> _SumT | Literal[0]: ... if sys.version_info >= (3, 8): @overload - def sum(__iterable: Iterable[_T], start: _S) -> _T | _S: ... + def sum(__iterable: Iterable[_SumT], start: _SumS) -> _SumT | _SumS: ... else: @overload - def sum(__iterable: Iterable[_T], __start: _S) -> _T | _S: ... + def sum(__iterable: Iterable[_SumT], __start: _SumS) -> _SumT | _SumS: ... # The argument to `vars()` has to have a `__dict__` attribute, so can't be annotated with `object` # (A "SupportsDunderDict" protocol doesn't work)