Skip to content

builtins.sum: Spurious error for operands having __add__ defined using partialmethod #7739

@kaushikcfd

Description

@kaushikcfd

Here's a minimal reproducer:

from __future__ import annotations
from functools import partialmethod

class A:
    def my_add(self, other: A, reverse: bool) -> A:
        return self

    __add__ = partialmethod(my_add, reverse=False)

a = A()
aa = A()
aaa = A()
result = sum([aa, a], start=aaa)

And the commands to reproduce it:

$ mypy --version
mypy 0.950 (compiled: yes)

$ mypy --show-error-codes --strict  mypy_bug_report.py 
mypy_bug_report.py:15: error: No overload variant of "sum" matches argument types "List[A]", "A"  [call-overload]
mypy_bug_report.py:15: note: Possible overload variants:
mypy_bug_report.py:15: note:     def [_SumT <: _SupportsSum] sum(Iterable[_SumT]) -> Union[_SumT, Literal[0]]
mypy_bug_report.py:15: note:     def [_SumT <: _SupportsSum, _SumS <: _SupportsSum] sum(Iterable[_SumT], start: _SumS) -> Union[_SumT, _SumS]
Found 1 error in 1 file (checked 1 source file)

Related #7735, #7578

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions