basedpyright
basedpyright copied to clipboard
`isinstance` checks on classes with generics should narrow to the generic's bound if it's covariant, and `Never` if it's contravariant
Code sample in basedpyright playground
class Foo[T: int | str]:
def foo(self, other: object):
if isinstance(other, Foo):
reveal_type(other) # Foo[Unknown], should be Foo[int | str]
if the generic is covariant it should narrow to Foo[int | str] (or whatever the generic's bound is), and if it's contravariant it should narrow to Foo[Never] i think
It doesn't seem like there's enough information here to come to this conclusion because the other argument has no generic connection to self (The T is never used to annotate anything about other).
So the only conclusion I can see here is that other should be of type Foo[BoundOfT]
yeah that's what i meant sorry, updated the example to be more clear