Closed
Description
Bug Report
When using generic Callables as parameters, the error is correctly reported, but it's reported for different argument than the one which is in fact wrong.
To Reproduce
from typing import Callable, TypeVar, List
T1 = TypeVar('T1')
T2 = TypeVar('T2')
def bigfunc(
a: int,
b: T1,
c: Callable[[T1], T2],
d: Callable[[T2], str],
) -> None:
res = d(c(b))
print(f'{a=}, {b=}, {res=}')
# should be:
# c_func(x: float) -> List[float]:
def c_func(x: float) -> None:
pass
def d_func(y: List[float]) -> str:
return str(y)
bigfunc(1, 0.1, c_func, d_func)
Expected Behavior
I would expect mypy to complain about 3rd argument (c - c_func
).
Actual Behavior
Mypy complains about 1st argument, which is 100% correct (a: int
)
a.py:24: error: Cannot infer type argument 1 of "bigfunc" [misc]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.16.0
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used: 3.11.2