Skip to content

Report an error if *args or **kwargs are passed when all other arguments are filled. #19244

Open
@chriselion

Description

@chriselion

Bug Report
You can pass **kwargs or *args to a function, even if all of its arguments are already passed. I would expect this to raise an error, since it's only valid for empty kwargs and args.

To Reproduce
playground link

def f(x: int) -> int:
    return x + 1
    
def g(x: int, **kwargs) -> int:
    return f(x, **kwargs)
    
def h(x: int, args: list[int]) -> int:
    return f(x, *args)

g(1, bar=42)
h(2, [])
h(3, [1337])

Expected Behavior
In both g and h, the x argument is specified, so I would expecting passing **kwargs or *args to produce an error, since they can never correctly pass additional arguments.

Actual Behavior

Success: no issues found in 1 source file

Your Environment
I tried several versions of mypy (including 1.16.0 and master) with python3.12 in mypy playground.
I tried with both with and without --check-untyped-defs

** Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    featuretopic-callsFunction calls, *args, **kwargs, defaults

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions