ParamSpec with Concatenate issue when function has union and kw args with strict=True
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Hi,
Found a strange issue triggered by strict only when kw-args are present in the function.
Below I believe that both function should either pass or fail (I think the correct behavior is pass here)
For reference pyright finds no issues in this snippet
Bug Report
(A clear and concise description of what the bug is.)
To Reproduce
# Ideally, a small sample program that demonstrates the problem.
# Or even better, a reproducible playground link https://mypy-play.net/ (use the "Gist" button)
from typing import Any, Callable, Concatenate, ParamSpec, TypeVar
P = ParamSpec("P")
T = TypeVar("T")
def go(x: Callable[Concatenate[str, P], T], *a: P.args, **k: P.kwargs) -> T:
return x("foo", *a, **k)
def ok(a: str | int, one: int) -> int:
return 1
def error(a: str | int, one: int, **kw: Any) -> int:
return 2
go(ok, 1)
go(error, 1)
mypy playground link here: https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=22221f205a86573a0c4db8cb529dc824
Expected Behavior
No error is reported
Actual Behavior
main.py:15: error: Argument 1 to "go" has incompatible type "Callable[[str | int, int, KwArg(Any)], int]"; expected "Callable[[str, int, KwArg(Any)], int]" [arg-type]
main.py:15: note: This is likely because "error" has named arguments: "a". Consider marking them positional-only
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.9.0
- Mypy command-line flags:
--strict - Mypy configuration options from
mypy.ini(and other config files): - - Python version used: 3.12
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 by running the supplied Python snippet in the linked mypy playground with Python 3.12 and --strict, then compare the diagnostics for go(ok) and go(error). Done means the ParamSpec and Concatenate case behaves consistently with the stated expectation and has regression coverage in mypy.
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
- 45/100