You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
builtins.sum: Spurious error for operands having __add__ defined using partialmethod #7739
changed the title [-]`builtins.sum`: Spurious error for operand error having `__add__` defined using `partialmethod`[/-][+]`builtins.sum`: Spurious error for operands having `__add__` defined using `partialmethod`[/+]on Apr 29, 2022
This still (unsurprisingly) reproduces after the recent changes to the sum stub. Here's the current error message:
(.venv) C:\Users\alexw\coding\typeshed>mypy test.py --strict --show-error-codes --custom-typeshed-dir .
test.py:13: error: No overload variant of "sum" matches argument types "List[A]", "A" [call-overload]
test.py:13: note: Possible overload variants:
test.py:13: note: def sum(__iterable, Iterable[bool], start: int = ...) -> int
test.py:13: note: def [_SupportsSumNoDefaultT <: _SupportsSumWithNoDefaultGiven] sum(__iterable, Iterable[_SupportsSumNoDefaultT]) -> Union[_SupportsSumNoDefaultT, Literal[0]]
test.py:13: note: def [_AddableT1 <: SupportsAdd[Any, Any], _AddableT2 <: SupportsAdd[Any, Any]] sum(__iterable, Iterable[_AddableT1], start: _AddableT2) -> Union[_AddableT1, _AddableT2]
Found 1 error in 1 file (checked 1 source file)
The reason why there's now an error where previously there was none is almost certainly due to changes made in typeshed between 0.942 and 0.950 that made the stub forsum` more complicated. Nonetheless, I feel like this is sort-of a bug in mypy's understanding of higher-order callables rather than a bug in the stub. In an ideal world, mypy should be able to understand that the arguments being passed in here match the third overload here:
I agree with @AlexWaygood. The output hasn't changed much with mypy 1.11.2. A reveal_type on A.__add__ reveals def (*Any, **Any) -> foo.A. This should match sum's third overload, but doesn't for some reason. This looks like a problem with mypy to me.
Activity
[-]`builtins.sum`: Spurious error for operand error having `__add__` defined using `partialmethod`[/-][+]`builtins.sum`: Spurious error for operands having `__add__` defined using `partialmethod`[/+]inducer commentedon Apr 29, 2022
It appears that this is a regression. mypy 0.942 does not object to the code in the OP.
AlexWaygood commentedon Jun 13, 2022
This still (unsurprisingly) reproduces after the recent changes to the
sumstub. Here's the current error message:The reason why there's now an error where previously there was none is almost certainly due to changes made in typeshed
between 0.942 and 0.950 that made the stub forsum` more complicated. Nonetheless, I feel like this is sort-of a bug in mypy's understanding of higher-order callables rather than a bug in the stub. In an ideal world, mypy should be able to understand that the arguments being passed in here match the third overload here:typeshed/stdlib/builtins.pyi
Lines 1664 to 1665 in 1828ba2
srittau commentedon Sep 2, 2024
I agree with @AlexWaygood. The output hasn't changed much with mypy 1.11.2. A
reveal_typeonA.__add__revealsdef (*Any, **Any) -> foo.A. This should matchsum's third overload, but doesn't for some reason. This looks like a problem with mypy to me.