Open
Description
Bug Report
At runtime the following code snippet:
def f(*, x: int = 9, y:int = 8) -> None:
pass
kwargs = {"x": 1, "y": 2}
f(*kwargs)
results in TypeError: f() takes 0 positional arguments but 2 were given. However, mypy does not report any issues.
To Reproduce
- Execute python interpreter for the code snipped above.
- Run mypy for the code snippet above.
Expected Behavior
Mypy should yield an error. For example pytype yields the following error:
Function f expects 0 arg(s), got 2 [wrong-arg-count]
Expected: (*, x, y)
Actually passed: (_, _)
Actual Behavior
Success: no issues found in 1 source file
Your Environment
- Mypy version used: 0.931
- Mypy command-line flags: None. Simply
mypy <FILENAME>
. - Mypy configuration options from
mypy.ini
(and other config files): N/A (defaults) - Python version used: 3.8.2
- Operating system and version: Mac OS Big Sur
Metadata
Metadata
Assignees
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
ktbarrett commentedon Feb 18, 2022
As I stated on the gitter, pytype is doing a lot keeping the number of elements in the literal dict around, I think the suggestion is overkill for such a corner case (though it might be a good long term goal) and only works for this minimal example and not in the common case. An appropriate solution might be to check when splatting that the function being called has no positional (or keyword in the other case) arguments and error, since it is likely not what the user intended.
[-]False negative for keyword only arguments with default values[/-][+]Only allow splatting iterables if function takes at least one positional arg[/+]hauntsaninja commentedon Feb 19, 2022
Changing the title to Kaleb's suggested action item.