python / python/mypy

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

Open
#19,244 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature topic-calls
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the linked mypy playground reproduction and compare the behavior described for g and h. Review related issues 13380 and 12206 for existing context and scope. Done means mypy reports the invalid splatted-argument calls while preserving valid empty *args and **kwargs cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.