microsoft / microsoft/pyright

False positive "reportArgumentType" if ParamSpec is inferred as generic argument

Open
#10,733 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

```python
from typing import Any, Callable, Final, Protocol, overload

class MyCallable[F](Protocol):
call: Final[F]

class ImplCall:
@overload
def call(self, a: str, b: str) -> str: ...
@overload
def call(self, a: int, b: int) -> int: ...
def call(self, a: Any, b: Any) -> Any:
assert False

def takes_call[**P, R](f: MyCallable[Callable[P, R]]) -> Callable[P, R]:
assert False

def main():
# Argument of type "ImplCall" cannot be assigned to parameter "f" of type "MyCallable[(**P@takes_call) -> R@takes_call]" in function "takes_call"
# "ImplCall" is incompatible with protocol "MyCallable[(**P@takes_call) -> R@takes_call]"
# Type parameter "F@MyCallable" is covariant, but "Overload[(a: str, b: str) -> str, (a: int, b: int) -> int]" is not a subtype of "(**P@takes_call) -> R@takes_call"
# No overloaded function matches type "(**P@takes_call) -> R@takes_call" (reportArgumentType)
res = takes_call(ImplCall())

# return type is correct
# Type of "res" is "Overload[(a: str, b: str) -> str, (a: int, b: int) -> int]"
reveal_type(res)
```
The return type is inferred correctly so I would expect this to produce no error.

```
pyright 1.1.403
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the inline Python reproducer using pyright 1.1.403, focusing on the ParamSpec inference in takes_call and the protocol compatibility diagnostic. Confirm the current reportArgumentType error and reveal_type result, then verify that the diagnostic is removed while the overload return type remains correctly inferred.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.