Error handling wrappers with `**kwargs` syntax
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
mypy seems to be unable to pass down the types of **kwargs arguments properly.
To Reproduce
def my_function(flag: bool = True, **kwargs: str) -> None:
...
def wrapper(**kwargs: str) -> None:
my_function(**kwargs)
Actual Behavior
main.py:6: error: Argument 1 to "my_function" has incompatible type "**Dict[str, str]"; expected "bool" [arg-type]
Found 1 error in 1 file (checked 1 source file)
Expected Behavior
I would expect no errors. Though I can see that inputting flag="hello" could cause issues, although the error message does not help in identifying this. Also, in that case, I would expect rewriting the wrapper like below would satisfy mypy (it doesn't):
def wrapper(**kwargs: str) -> None:
if "flag" in kwargs:
raise
my_function(**kwargs)
Your Environment
- Mypy version used: 1.3.0
- Python version used: 3.11.2
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
The issue names no repository files or tests; start with the minimal Python reproducer and its linked mypy-play playground. Trace how calls using **kwargs are checked, then verify the valid wrapper is accepted while the flag="hello" case receives appropriate handling, adding a regression test once the relevant checker tests are located.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100