Skip to content

mypy accepts passing args= to a function taking *args #19019

Open
@nneonneo

Description

@nneonneo

Bug Report

mypy does not flag an error when attempting to pass keyword args= to a function that takes *args, even though that is entirely nonsensical.

To Reproduce

https://mypy-play.net/?flags=verbose%2Cstrict&mypy=latest&python=3.12&gist=4e82d2194b167b990da83b77b26bfdf9

def foo(*args: str) -> tuple[str, ...]:
    return args

print(foo(args="a"))

This code throws TypeError: foo() got an unexpected keyword argument 'args' when run.

Expected Behavior

mypy should flag this as an error, as the code throws a TypeError at runtime.

Actual Behavior

mypy reports no errors, even on --strict: Success: no issues found in 1 source file. mypy will attempt to typecheck the argument passed as args= according to the type of args in the function signature, even though passing the argument this way is completely illegal.

Your Environment

  • Mypy version used: mypy 1.15.0 (compiled: yes)
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files): (none)
  • Python version used: Python 3.10.11 (v3.10.11:7d4cc5aa85, Apr 4 2023, 19:05:19) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-callsFunction calls, *args, **kwargs, defaults

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions