python / python/mypy

Incorrect behavior for functions with keyword-only arguments and **kwargs

Open
#15,317 2 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report
mypy reports a arg-type error Argument 2 to "send_command" has incompatible type "**Dict[str, object]"; expected "Optional[float]" [arg-type] for a valid function invocation.

To Reproduce

def send_command(name: str, *, timeout: Optional[float] = None, **params: Any):
    print(name, params, timeout)

send_command("Test", **{"p1": "abc"})

mypy Playground

Expected Behavior
The code above should typecheck without any error.

Actual Behavior
I get the following mypy error:

main.py:7: error: Argument 2 to "send_command" has incompatible type "**Dict[str, str]"; expected "Optional[float]"  [arg-type]

Your Environment

  • Mypy version used: 1.3.0
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.11

See also

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 reported Python 3.11 reproducer in main.py with mypy 1.3.0 and compare the diagnostic with the expected behavior. Read the linked typing discussion and related issue #5382 for context; done means the valid keyword-only call typechecks without an arg-type error.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.