The function d takes two functions, an original, and a wrapper. The wrapper function needs to take the original function and its parameters.
Mypy is failing to infer the paramspec for the case where the wrapper indicates poisitional parameters. Unfortunately I'm too ignorant of the specifics of ParamSpec to know if this is working correctly or not π’, but I would think that P would get inferred as [int]
@ilevkivskyi Can you provide any insight for this case?
FYI: This did not show an error in mypy 1.5.1, it inferred P as [i: int].
from collections.abc import Callable
from typing import Concatenate, _P as P
from mypy_extensions import Arg
def o(i: int) -> None:
print(i)
def f1(c: Callable[[Arg(int, "i")], None], /, i: int) -> None:
c(i)
def f2(c: Callable[[int], None], /, i: int) -> None:
c(i)
def d(f: Callable[P, None], fn: Callable[Concatenate[Callable[P, None], P], None]) -> Callable[P, None]:
def inner(*args: P.args, **kwargs: P.kwargs) -> None:
fn(f, *args, **kwargs)
return inner
d(o, f1) # works
d(o, f2)
# main.py:22: error: Cannot infer type argument 1 of "d" [misc]
# main.py:22: error: Argument 1 to "d" has incompatible type "Callable[[Callable[[int], None], int], None]"; expected "Callable[[Callable[[VarArg(Any), KwArg(Any)], None], VarArg(Any), KwArg(Any)], None]" [arg-type]
The function
dtakes two functions, an original, and a wrapper. The wrapper function needs to take the original function and its parameters.Mypy is failing to infer the paramspec for the case where the wrapper indicates poisitional parameters. Unfortunately I'm too ignorant of the specifics of
ParamSpecto know if this is working correctly or not π’, but I would think thatPwould get inferred as[int]@ilevkivskyi Can you provide any insight for this case?
FYI: This did not show an error in mypy 1.5.1, it inferred
Pas[i: int].