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

variance inferred oincorrectly when class has both a covariant and contravariant generic and instance attribute is assigned without a type annotation #18147

Open
DetachHead opened this issue Nov 12, 2024 · 0 comments
Labels
bug mypy got something wrong topic-pep-695 Issues related to PEP 695 syntax topic-type-variables

Comments

@DetachHead
Copy link
Contributor

from typing import Never


class Foo[in_T, out_T]:
    def __init__(self, *, value: out_T):
        a: Foo[Never, object] = self # error (incorrect)
        self.__a = value
        reveal_type(self.__a) # out_T`2

    def asdf(self, value: in_T) -> out_T: ...


class Bar[in_T, out_T]:
    def __init__(self, *, value: out_T):
        a: Bar[Never, object] = self # no error (correct)
        self.__a: out_T = value
        reveal_type(self.__a) # out_T`2

    def asdf(self, value: in_T) -> out_T: ...

playground

(originally raised in #18118 but i messed up the minimal repro)

@DetachHead DetachHead added the bug mypy got something wrong label Nov 12, 2024
@brianschubert brianschubert added topic-type-variables topic-pep-695 Issues related to PEP 695 syntax labels Nov 12, 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 topic-pep-695 Issues related to PEP 695 syntax topic-type-variables
Projects
None yet
Development

No branches or pull requests

2 participants