Misleading error when using a dict of keyword args
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
When passing at least part of the function parameter as an ** expanded dictionary, if one or more of the parameters is missing, a misleading "incomaptible type" is shown, instead of "missing parameter".
See also stackoverflow for a way to get a better (but still not correct, since it lists all the parameters as missing) message
To Reproduce
def my_func(a: str = 'Hello', b: bool = False, c: int = 1):
return a, b, c
input_kwargs = {'b': True}
result = my_func(**input_kwargs)
or see the gist
Actual Behavior
main.py:14: error: Argument 1 to "fib" has incompatible type "**Dict[str, int]"; expected "str"
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 0.812 (or 0.981 on mypy-play)
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files):
check_untyped_defs = True
show_error_codes = True
pretty = True
ignore_missing_imports = True
- Python version used: 3.8 (or 3.10 on mypy-play)
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
Reproduce the diagnostic with the provided my_func and input_kwargs example, or use the linked mypy-play gist, then trace the checker entry point for calls using **-expanded dictionaries. Done means a missing parameter is reported as missing rather than as an incompatible type, with coverage for the shown Python 3.8/3.10 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
- 35/100