Skip to content

Incorrect behavior for functions with keyword-only arguments and **kwargs #15317

@jrast

Description

@jrast

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"})

mypy Playground

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions