Skip to content

Only allow splatting iterables if function takes at least one positional arg #12206

Open
@piotrfilipiuk

Description

@piotrfilipiuk

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

  1. Execute python interpreter for the code snipped above.
  2. 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

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions