False positive when callback protocol uses a function-scoped type variable
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
This appears to be a regression as the example code in #8177 fails to type check.
Please consider the following code:
```python
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported snippet with Pyright 1.1.405 from the command line and confirm the false-positive return-type diagnostic. Trace the callable protocol and function-scoped type-variable compatibility checks, then verify that `func1` accepts `make_a` without an error while other diagnostics remain unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100