Incorrect behavior for functions with keyword-only arguments and **kwargs
Nobody has claimed this yet.
- 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"})
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
- This python/typing discussion: https://github.com/python/typing/discussions/1406
- Maybe related: #5382
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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