[1.12 regression] `functools.partial` and ParamSpec
Bug Report
A function that takes in a function with a broad signature and returns a narrowed partially-applied function now reports error: Too few arguments [call-arg] in mypy 1.12.
To Reproduce
from functools import partial
from typing import ParamSpec, TypeVar, Callable, Concatenate
P = ParamSpec("P")
R = TypeVar("R")
def partializer(
func: Callable[Concatenate[int, str, P], R],
one: int,
two: str,
) -> Callable[P, R]:
return partial(func, one, two)
Expected Behavior
mypy has not reported any issue with this incantation historically, and should still not report on (what, as far as my understanding allows, is) valid code.
Actual Behavior
main.py:12: error: Too few arguments [call-arg]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.12
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.9, 3.11, 3.12
This is probably caused by https://github.com/python/mypy/pull/17323 See also https://github.com/python/mypy/pull/17355
Yes, the two linked PRs are very relevant: #17355 supports partial application to ParamSpec callables, and without it whole support for ParamSpec+partial is dead. I just resurrected that PR, but I'm not sure if it's the best approach: I would love to hear some feedback. It feels like a right direction, but involves too many partial-specific additions to mypy core.