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

overriding variable with property: error Signature incompatible with supertype #8185

Closed
Kamik423 opened this issue Dec 20, 2019 · 1 comment

Comments

@Kamik423
Copy link

class A:
    foo: str = "foo"

class B(A):
    @property
    def foo(self) -> str:
        return "bar"

print(B().foo) # "bar"

When overriding a variable with a property I get the error:

mypy: error
Signature of "foo" incompatible with supertype "A"

The code executes fine, though.

$ mypy --version
mypy 0.750
$ python3 --version
Python 3.7.5

The only idea I have is, that this overrides a variable which is both an instance variable and a class variable with one that is instance only.

@ilevkivskyi
Copy link
Member

This code is actually unsafe and mypy is right, you can't override a writeable attribute with a read-only one.

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

2 participants