Skip to content

Presence of property in Protocol causes false positive in multiple inheritance scenario #16873

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

Closed
slanzmich opened this issue Feb 5, 2024 · 3 comments
Labels
bug mypy got something wrong topic-protocols

Comments

@slanzmich
Copy link

Bug Report

I'm getting a false positive from the following example

from typing import Protocol
from typing_extensions import Self

class P(Protocol):
    # Removing the property makes the problem disappear
    @property
    def x(self) -> int: ...

    def clone(self) -> Self: ...

class A:
    def clone(self) -> Self:
        return self

class B(A, P):
    @property
    def x(self) -> int:
        return 100
main.py:18: error: Definition of "clone" in base class "A" is incompatible with definition in base class "P"  [misc]

Obviously, A.clone does not actually clone the instance, but that is left out for clarity.

The false positive is not reported when I remove the property x from the protocol P.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.12&gist=fe15d8bc18aa7b61feb3e56fce615f47

@slanzmich slanzmich added the bug mypy got something wrong label Feb 5, 2024
@hauntsaninja
Copy link
Collaborator

Thanks, looks like it's not just property, basically anything else in the Protocol seems to trigger the error:

from typing import Protocol, Self

class P(Protocol):
    def foo(self) -> None: ...
    def clone(self) -> Self: ...

class A:
    def clone(self) -> Self: ...

class B(A, P):
    pass

(As a workaround you can consider not explicitly inheriting from the protocol)

@sterliakov
Copy link
Collaborator

This passes on current master and was fixed by #18465 - sorry, I missed more than one related issue...

@hauntsaninja
Copy link
Collaborator

Great!

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

No branches or pull requests

4 participants