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

write-able properties and fields are treated as covariant when they should be invariant #11975

Closed
KotlinIsland opened this issue Jan 12, 2022 · 1 comment
Labels
bug mypy got something wrong

Comments

@KotlinIsland
Copy link
Contributor

class A:
    a: int = 10
    @property
    def foo(self) -> int:
        return 1
    @foo.setter
    def foo(self, value: int) -> None:
        ...
class B(A):
    a: bool = True
    @property
    def foo(self) -> bool:
        return True
    
    @foo.setter
    def foo(self, value: bool) -> None:
        ...

def foo(a: A) -> None:
    a.a = 10
    a.foo = 10
    
    
b = B()
foo(b)
reveal_type(b.a)  # bool, at runtime it's int
reveal_type(b.foo)  # bool, at runtime it's int

https://mypy-play.net/?mypy=master&python=3.10&flags=strict&gist=9433ff90606ac67ec9728212af1edec1

@KotlinIsland KotlinIsland added the bug mypy got something wrong label Jan 12, 2022
@hauntsaninja
Copy link
Collaborator

Thanks, duplicate of #3208

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

2 participants