Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nneonneo opened this issue May 3, 2025 · 0 comments · Fixed by #19022
Closed

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

nneonneo opened this issue May 3, 2025 · 0 comments · Fixed by #19022
Labels
bug mypy got something wrong topic-calls Function calls, *args, **kwargs, defaults

Comments

@nneonneo
Copy link

nneonneo commented May 3, 2025

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
@nneonneo nneonneo added the bug mypy got something wrong label May 3, 2025
@sterliakov sterliakov added the topic-calls Function calls, *args, **kwargs, defaults label May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-calls Function calls, *args, **kwargs, defaults
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants