Open robert-bn opened 2 weeks ago
Thanks for the issue. I agree this looks like a bug in pyright's constraint solver. I'll investigate further.
In the meantime, you can work around the issue by making the type parameter used in PolymorphicListItemGetter
a class-scoped type variable rather than a method-scoped type variable.
class PolymorphicListItemGetter[T](Protocol):
def __call__(self, l: list[T], /) -> T: ...
Consider the following code:
pyright doesn't raise an error in the definition of
upcast
, indicatingPolymorphicListItemGetter
can be widened toGetter[list[HasFoo], HasFoo]
, but when it is passed as an argument directly tocompose_getters
pyright is unable to widen its type.I would expect there to be no type error, as
PolymorphicListItemGetter
is a subtype ofGetter[list[HasFoo], HasFoo]
.The error raised by pyright is
Tested with pyright cli version 1.1.370