Skip to content

issue with ParamSpec and Callable of Callables #16405

Closed

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

Activity

  1. ilevkivskyi commented on Nov 4, 2023

    @ilevkivskyi
    Member

    This may be caused by #15896, IIRC. It was kind of an intentional trade-of. We added support for some more common cases (e.g. generic apply with positional arguments) knowing this may cause some regressions for more tricky cases (e.g. those involving keyword-only arguments). The decision was to see what use cases people actually need, and add some special-casing accordingly.

    Since this is quite a tricky thing, the fix will not be available in 1.7, even though this is technically a regression (unless I will find a low-risk solution), fix will probably be available in 1.8.

  2. self-assigned this
    on Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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