pyright
pyright copied to clipboard
False positive when callback protocol uses a function-scoped type variable
This appears to be a regression as the example code in #8177 fails to type check.
Please consider the following code:
from typing import Protocol
class A[T,U]: ...
class BProto(Protocol):
def __call__[T](self) -> A[list[T], T]: ...
def make_a[T]() -> A[list[T], T]: ...
def func1() -> BProto:
return make_a
Pyright 1.1.405 run from command-line reports the following above the above code:
error: Type "() -> A[list[T@make_a], T@make_a]" is not assignable to return type "BProto"
Type "() -> A[list[T@make_a], T@make_a]" is not assignable to type "() -> A[list[T@__call__], T@__call__]"
Function return type "A[list[T@make_a], T@make_a]" is incompatible with type "A[list[T@__call__], T@__call__]"
"A[list[T@make_a], T@make_a]" is not assignable to "A[list[T@__call__], T@__call__]"
Type parameter "T@A" is covariant, but "list[T@make_a]" is not a subtype of "list[T@__call__]"
"list[T@make_a]" is not assignable to "list[T@__call__]"
Type parameter "U@A" is covariant, but "T@make_a" is not a subtype of "T@__call__"
Type "T@make_a" is not assignable to type "T@__call__" (reportReturnType)
But make_a is an instance of BProto, so I would expect there not to be any type error.