python / python/mypy

__i<magic>__ method incompatible with __<magic>__ of superclass

Open
#6,225 7 comments 0 reactions 1 assignee View on GitHub

@Michael0x2a is already working on this.

Since Jan 19, 2019.

bug documentation needs discussion priority-1-normal
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

I'm recieving an a error within folowing code:

class A:
    def __add__(self, other) -> int:
        ...
    def __iadd__(self, other) -> 'A':
        ...

class C(A):
    #  error: Return type of "__iadd__" incompatible with "__add__" of supertype "A"
    def __iadd__(self, other) -> 'C':
        ...

I'm not sure that __add__ and __iadd__ methods have to be compatible.
And, if belief to the MyPy in the signature of class A, that not produce the error, MyPy also doesn't think they have to be compatible...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.