Skip to content
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

Bug: Types not checked properly when variadic function calls non-variadic function #6308

Closed
maxrothman opened this issue Feb 2, 2019 · 1 comment

Comments

@maxrothman
Copy link

  • Mypy: 0.660
  • Python: 3.7.2

Given the following code:

def variadic(*args: str, **kwargs: str) -> None:
    nonvariadic(*args, **kwargs)

def nonvariadic(a: str, b: str) -> None:
    print(a, b)

variadic()

Running mypy --strict yields no warnings. There's an obvious runtime error though:

TypeError: nonvariadic() missing 2 required positional arguments: 'a' and 'b'

Using a "proxy function" that takes *args, **kwargs is a pretty common pattern in real-world code, so this seems like something mypy should support.

@JelleZijlstra
Copy link
Member

The general reason that mypy doesn't catch this is that type checking is local to individual functions, and there's no obvious type error in either function taken by itself.

The problem you're pointing out is real, but unfortunately there doesn't appear to be a simple solution. python/typing#270 has a concrete proposal that would cover your use case, so closing this issue in favor of the typing one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants