Skip to content

issue with ParamSpec and Callable of Callables #16405

Closed
@graingert

Description

@graingert

Bug Report
When using ParamSpec and passing a Callable that takes a Callable, mypy 1.6.0, 1.6.1 and master rejects the input, this is a regression from 1.5.1

To Reproduce

from typing import *

T_Retval = TypeVar("T_Retval")
P = ParamSpec("P")


def run(
    func: Callable[[], T_Retval],
    *args: object,
    backend: str = "asyncio",
) -> T_Retval:
    return func()


def run_portal():
    pass


def submit(
    func: Callable[P, T_Retval],
    /,
    *args: P.args,
    **kwargs: P.kwargs,
) -> T_Retval:
    return func(*args, **kwargs)


submit(
    run,
    run_portal,
    backend="asyncio",
)

https://mypy-play.net/?mypy=1.6.1&python=3.11&gist=e282d121f479fcb77ec89daeb2a07b60

Expected Behavior

Should pass

Actual Behavior

main.py:29: error: Argument 1 to "submit" has incompatible type "Callable[[Callable[[], T_Retval], VarArg(object), DefaultNamedArg(str, 'backend')], T_Retval]"; expected "Callable[[Callable[[], Any], str], T_Retval]"  [arg-type]

Your Environment

  • Mypy version used: 1.5.1 (passes) 1.6.1, 1.6.0, master (fails)
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.11

Metadata

Metadata

Assignees

Labels

bugmypy got something wrongtopic-paramspecPEP 612, ParamSpec, Concatenate

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions