No error emitted with `ParamSpec` on a signature that is a union of callables with `ParamSpec` and without `ParamSpec`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
See discussion on pyright at : https://github.com/microsoft/pyright/issues/6796
mypy doesn't emit an error, but pyright does, and it isn't clear which is correct!
We're trying to support something with pandas with DataFrame.pipe() that allows functions with any kind of argument list to be passed. But the function can be specified in one of two ways:
- as a function
- as a tuple, with the tuple being the name of an argument and the function
To Reproduce
from typing import Callable, Concatenate
from typing_extensions import ParamSpec
P = ParamSpec("P")
def func1(x: int):
print(x)
def func2(x: int, /, y: str):
print(x)
def accept_func(
f: Callable[Concatenate[int, P], None] | tuple[int, Callable[..., None]],
*args: P.args,
**kwargs: P.kwargs,
) -> None:
if isinstance(f, tuple):
if args:
f[1](f[0], args)
else:
f[1](f[0])
else:
f(5)
accept_func(func1)
accept_func((2, func1))
accept_func((3, func2), "abc")
Expected Behavior
pyright reports:
pspec.py:26:9 - error: Arguments for ParamSpec "P@accept_func" are missing (reportGeneralTypeIssues)
pspec.py:29:1 - error: Arguments for ParamSpec "P@accept_func" are missing (reportGeneralTypeIssues)
pspec.py:30:25 - error: Arguments for ParamSpec "P@accept_func" are missing (reportGeneralTypeIssues)
pyright authors think mypy should report all 3. See discussion in linked issue.
Actual Behavior
mypy reports:
Success: no issues found in 1 source file
Your Environment
- Mypy version used: 1.7.1
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.11.3
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
Start with the provided ParamSpec and Callable-union reproduction, then read the linked pyright discussion to understand the competing interpretations. Run it against mypy with the stated environment and trace the ParamSpec checking behavior; done means the handling is resolved and covered by a regression test or documented as intentional.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100