Skip to content

ParamSpec does not consider substitution of @overloads #13540

Description

@sbrudenell

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions