Skip to content

Multiple dict unpacking for function arguments gives type error #4708

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
bmerrison opened this issue Mar 9, 2018 · 0 comments · Fixed by #9573
Closed

Multiple dict unpacking for function arguments gives type error #4708

bmerrison opened this issue Mar 9, 2018 · 0 comments · Fixed by #9573

Comments

@bmerrison
Copy link

When I run the following code through MyPy:

def fn(a: int, b: int, c: int) -> None:
    print((a, b, c))

fn(**{'a': 10}, **{'b': 20, 'c': 30})

I receive the following:

$ python -m mypy mypy_problem.py
mypy_problem.py:8: error: Too many arguments for "fn"

I expect this to not give an error because as far as I know it's valid python code - it works at least! A workaround is to wrap the whole thing in another dictionary, i.e.:

fn(**{**{'a': 10}, **{'b': 20, 'c': 30}})

But this is messy and possibly introduces an additional overhead.

$ conda list | grep 'python\|mypy\|typed-ast'
mypy                      0.570                     <pip>
python                    3.5.2                         0    conda-forge
typed-ast                 1.1.0                     <pip>

I'm using Windows 7 64-bit.

msullivan pushed a commit that referenced this issue Oct 18, 2020
Fixes #4708
Allows for multiple ambiguous **kwarg unpacking in a call -- all ambiguous **kwargs will map to all formal args that do not have a certain actual arg.

Fixes #9395
Defers ambiguous **kwarg mapping until all other unambiguous formal args have been mapped -- order of **kwarg unpacking no longer affects the arg map.
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