I just merged a PR over at typeshed to improve the stub for builtins.sum. The first draft of the PR proposed defining sum like this:
import sys
from typing import *
class _SupportsSum(Protocol):
def __add__(self, __x: Any) -> Any: ...
_SumT = TypeVar("_SumT", bound=_SupportsSum)
_SumS = TypeVar("_SumS", bound=_SupportsSum)
@overload
def sum(__iterable: Iterable[_SumT]) -> Any | Literal[0]: ...
if sys.version_info >= (3, 8):
@overload
def sum(__iterable: Iterable[_SumT], start: _SumS) -> _SumT | _SumS: ...
else:
@overload
def sum(__iterable: Iterable[_SumT], __start: _SumS) -> _SumT | _SumS: ...
I think this should have triggered pyright's reportInvalidTypeVarUse check, as the TypeVar in the first overload is only used once. However, pyright reported no errors in our CI check.
(The PR was revised to correct this mistake before it was merged.)
I just merged a PR over at typeshed to improve the stub for
builtins.sum. The first draft of the PR proposed definingsumlike this:I think this should have triggered pyright's
reportInvalidTypeVarUsecheck, as the TypeVar in the first overload is only used once. However, pyright reported no errors in our CI check.(The PR was revised to correct this mistake before it was merged.)