Skip to content

Kwargs after ParamSpec.args should be tolerated #19506

Description

@kdkavanagh

Bug Report
I believe mypy's handling of ParamSpecs is slightly too restrictive. Currently, it validates that there are no args or kwargs after a ParamSpec.args argument other than **kwargs. I believe it's tolerable to have kwargs follow a ParamSpec.args

Related to #18278

To Reproduce

def f5(f: Callable[P, int], *args: P.args, extra_regular_arg: int, **kwargs: P.kwargs) -> int: ...  # E: Arguments not allowed after ParamSpec.args

def f6(f: Callable[P, int], *args: P.args, extra_kwarg: int = 123, **kwargs: P.kwargs) -> int: ...  # E: Arguments not allowed after ParamSpec.args

Expected Behavior
The first function above should continue to fail, while the second function should not throw an error

Activity

  1. brianschubert commented on Jul 25, 2025

    @brianschubert
    Collaborator

    Thanks for the issue! However, the behavior you suggest is not permitted by the typing spec, which states:

    Placing keyword-only parameters between the *args and **kwargs is forbidden.

    Both extra_regular_arg in f5 and extra_kwarg in f6 are keyword-only parameters, so mypy is correct to reject them. The reason for this restriction explained in the Rejected Alternatives section of the original PEP: https://peps.python.org/pep-0612/#concatenating-keyword-parameters

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

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions