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

Pyright fails to determine the variance of a type variable in a typing.Protocol #4674

Closed
LeeeeT opened this issue Feb 22, 2023 · 2 comments
Closed
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@LeeeeT
Copy link

LeeeeT commented Feb 22, 2023

For the following code Pyright incorrectly suggests that I change the variance of Foo to covariant.

from typing import Generic, Protocol, TypeVar

T_contra = TypeVar("T_contra", contravariant=True)

class Contra(Generic[T_contra]):
    ...

class Foo(Protocol[T_contra]):
    def f(self) -> Contra[T_contra]:
        ...
file.py:8:7 - error: Type variable "T_contra" used in generic protocol "Foo" should be covariant

pyright 1.1.295

@erictraut
Copy link
Collaborator

Thanks for the bug report. This will be fixed in the next release.

@erictraut erictraut added bug Something isn't working addressed in next version Issue is fixed and will appear in next published version labels Feb 22, 2023
erictraut pushed a commit that referenced this issue Feb 22, 2023
…rrect variance of a TypeVar used within a class. This addresses #4674.
@erictraut
Copy link
Collaborator

This is included in pyright 1.1.296, which I just published. It will also be included in a future release of pylance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants