Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signature incompatible with supertype when using static methods #9330

Closed
barisione opened this issue Aug 20, 2020 · 2 comments
Closed

Signature incompatible with supertype when using static methods #9330

barisione opened this issue Aug 20, 2020 · 2 comments

Comments

@barisione
Copy link

This code:

class Base:
    @staticmethod
    def method(n: int) -> None:
        print(n)


class Deriv(Base):
    def method(self, n: int) -> None:
        print(f"{n} from {self}")

Produces this:

$ mypy test_static.py
test_static.py:8: error: Signature of "method" incompatible with supertype "Base"
Found 1 error in 1 file (checked 1 source file)

When using mypy from git (mypy 0.790+dev.c231ee4fdca075582e1177a8ecea3f379ccaa784) with Python 3.8.

This is pretty similar to #4125 (attributes overwritten with properties) and could end up being fixed by #7724.
I'm still reporting the issue as I didn't see any mention of static methods in other issues.

@ilevkivskyi
Copy link
Member

FWIW mypy is correct here, this is not a safe override, since methods can be called on class objects:

x: Type[Base] = Deriv
x.method(42) # Oops, TypeError at runtime here

@i386x
Copy link

i386x commented Feb 17, 2022

On the other hand, this clashes with pylint: R0201: Method could be a function (no-self-use)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants