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

Failure when overriding an protocol attribute with a property in protocol subclass #13954

Closed
cmeyer opened this issue Oct 27, 2022 · 2 comments
Closed
Labels
bug mypy got something wrong

Comments

@cmeyer
Copy link

cmeyer commented Oct 27, 2022

Bug Report

Unexpected typing failure when subclassing protocol.

To Reproduce

mypy --strict f.py

f.py:

import typing

class B(typing.Protocol):
    field1: float

class D(B):
    @property
    def field1(self) -> float: return 0

    @field1.setter
    def field1(self, v: float) -> None: pass

class E:
    @property
    def field1(self) -> float: return 0

    @field1.setter
    def field1(self, v: float) -> None: pass

Expected Behavior

Both classes, D and E, should pass type checking.

Actual Behavior

The D class fails type checking:

f.py:7: error: Signature of "field1" incompatible with supertype "B"
f.py:8: error: Signature of "field1" incompatible with supertype "B"
Found 2 errors in 1 file (checked 1 source file)

Your Environment

Multiple environments.

% mypy --version
mypy 0.982 (compiled: yes)
@cmeyer cmeyer added the bug mypy got something wrong label Oct 27, 2022
@tmke8
Copy link
Contributor

tmke8 commented Oct 28, 2022

This was fixed by #13475 which hasn't been released yet, but you can try it out on mypy master.

@hauntsaninja
Copy link
Collaborator

Thanks for the issue report and thanks for linking the fix!

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

No branches or pull requests

3 participants