basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

explicit covariance on old `TypeVar`s is not checked at all unless the generic is the only part of the type annotation

Open DetachHead opened this issue 1 year ago • 1 comments

Code sample in basedpyright playground

from typing import Generic, TypeVar

T = TypeVar("T", covariant=True)

class Foo(Generic[T]):
    def b(self, value: T | int) -> None: ... # no error

DetachHead avatar Oct 10 '24 03:10 DetachHead

not just unions:

Code sample in basedpyright playground

from typing import Generic, TypeVar
from collections.abc import Sequence

T = TypeVar("T", covariant=True)

class Foo(Generic[T]):
    def asdf(self, value: Sequence[T]) -> None: # no error
        ...

DetachHead avatar Sep 29 '25 04:09 DetachHead