Bug Report
It looks like mypy only considers the first @overload of a function, when considering substitutions for a ParamSpec.
In particular this affects use of asyncio.to_thread(f, arg), if f has @overloads.
To Reproduce
importasynciofromcollections.abcimportCallablefromtypingimportoverloadfromtypingimportTypeVarfromtyping_extensionsimportParamSpec@overloaddeff(x: int) ->None:
...
@overloaddeff(x: str) ->None:
...
deff(x) ->None:
pass_P=ParamSpec("_P")
_R=TypeVar("_R")
# type signature modeled after asyncio.to_thread()defgeneric(func: Callable[_P, _R], *args: _P.args, **kwargs: _P.kwargs) ->_R:
...
# using first overload: passesgeneric(f, 1)
# using second overload: failsgeneric(f, "test")Expected Behavior
$ mypy t.py
Success: no issues found in 1 source file
Actual Behavior
$ mypy t.py
t.py:35: error: Argument 2 to "generic" has incompatible type"str"; expected "int"
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used:
mypy 0.971 (compiled: yes) - Mypy command-line flags:
mypy t.py - Mypy configuration options from
mypy.ini (and other config files): none - Python version used: 3.10.4
- Operating system and version: Ubuntu 22.04.1
Bug Report
It looks like
mypyonly considers the first@overloadof a function, when considering substitutions for aParamSpec.In particular this affects use of
asyncio.to_thread(f, arg), iffhas@overloads.To Reproduce
Expected Behavior
Actual Behavior
Your Environment
mypy 0.971 (compiled: yes)mypy t.pymypy.ini(and other config files): none