Skip to content

Bad error message for arguments between ParamSpec P.args and P.kwargs #13966

Closed
@JonathanPlasse

Description

@JonathanPlasse

Bug Report

ParamSpec P.args and P.kwargs are not defined when using explicit keyword argument.

To Reproduce

This code would be used to type anyio.run().

Link to mypy-play

from typing import ParamSpec, Awaitable, TypeVar, Callable, Any

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

def run(
    func: Callable[P, Awaitable[T_Retval]],
    *args: P.args,
    backend: str = "asyncio",
    backend_options: dict[str, Any] | None = None,
    **kwargs: P.kwargs,
) -> T_Retval:
    pass

but it works without explicit keyword arguments.

from typing import ParamSpec, Awaitable, TypeVar, Callable, Any

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

def run(
    func: Callable[P, Awaitable[T_Retval]],
    *args: P.args,
    **kwargs: P.kwargs,
) -> T_Retval:
    pass

Expected Behavior

It should be able to type and recognize that run() passes the rest of the arguments to the function a().

async def a(b: str, c: int) -> None:
    pass

run(a, "", c=0)

Actual Behavior

main.py:10: error: Name "P.args" is not defined
main.py:13: error: Name "P.kwargs" is not defined

Your Environment

  • Mypy version used: 0.981
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions