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

generic is incorrectly inferred as invariant if class uses Self type on an attribute #18334

Open
DetachHead opened this issue Dec 24, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@DetachHead
Copy link
Contributor

from typing import Self


class Foo[T]:
    instance: Self # commenting out this line makes the error go away

    def foo(self) -> T: ... # type:ignore[empty-body]


class Bar(Foo[int]): ...

# Incompatible types in assignment (expression has type "Bar", variable has type "Foo[object]")  [assignment]
foo: Foo[object] = Bar()

playground

@DetachHead DetachHead added the bug mypy got something wrong label Dec 24, 2024
@DetachHead DetachHead changed the title generic is incorrectly inferred as invariant if class uess Self type on an attribute generic is incorrectly inferred as invariant if class uses Self type on an attribute Dec 24, 2024
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

1 participant