Skip to content

Some combos of *args/**kwds in caller/callee not supported #1892

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
gvanrossum opened this issue Jul 18, 2016 · 1 comment · Fixed by #1964
Closed

Some combos of *args/**kwds in caller/callee not supported #1892

gvanrossum opened this issue Jul 18, 2016 · 1 comment · Fixed by #1964

Comments

@gvanrossum
Copy link
Member

This spawned off #1553. The mapping of argument type from a call site to a function definition is complicated by the existence of *args, **kwds, optional args, and keyword-only args.

For example, Python 3.5+ support multiple *args in a call! (But not in a definition.) So this (valid) code gives two errors while there should be none:

def f(*a: int) -> int: return sum(a)
f(*[1, 2, 3], *[4, 5], 6)  # E: Too many arguments for "f"
f(*(1, 2, 3), *(4, 5), 6)  # E: Too many arguments for "f"

(It also doesn't give a SyntaxError with --python-version=3.4 as it should.)

@gvanrossum gvanrossum added this to the Future milestone Jul 21, 2016
@gvanrossum
Copy link
Member Author

Here's another example of something that doesn't work:

def f(*a: int) -> None:
    print(a)

f(1, 2, 3, 4)  # ok
f(1, 2, *[3, 4])  # ok
f(*[1, 2], 3, 4)  # E: Too many arguments for "f"

The reason in this case is that [1, 2] is treated as just List[int] and a *x argument where x is a sequence type, when the corresponding formal is also a * argument, is assumed to "fill up" the entire *args.

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

Successfully merging a pull request may close this issue.

1 participant