pythonmypypython-typingmixins

From classmethod to staticmethod: mypy complains for mixin but not inheritance


When I use inheritance, mypy doesn't complain when I change a classmethod into a staticmethod:

class A:
    @classmethod
    def f(cls, a: int) -> int:
        return a

class B(A):
    @staticmethod
    def f(a: int) -> int:
        return a+1

However, if I'm using a mixin to do the same:

class C:
    @staticmethod
    def f(a: int) -> int:
        return a+1

class D(C, A):
    pass

mypy gives the following error (on the class D(C, A): line):

Definition of "f" in base class "C" is incompatible with definition in base class "A"

Why is that so?


Solution

  • Actually it was a bug fixed in mypy 0.710, probably by #6720.