Skip to content

bpo-40830: Make sure that keyword arguments are merged into the arguments dictionary when dict unpacking and keyword arguments are interleaved. #20553

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

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Lib/test/test_extcall.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@
>>> f(1, 2, 3, *(4, 5), x=6, y=7, **UserDict(a=8, b=9))
(1, 2, 3, 4, 5) {'a': 8, 'b': 9, 'x': 6, 'y': 7}

Mix keyword arguments and dict unpacking

>>> d1 = {'a':1}

>>> d2 = {'c':3}

>>> f(b=2, **d1, **d2)
() {'a': 1, 'b': 2, 'c': 3}

>>> f(**d1, b=2, **d2)
() {'a': 1, 'b': 2, 'c': 3}

>>> f(**d1, **d2, b=2)
() {'a': 1, 'b': 2, 'c': 3}

>>> f(**d1, b=2, **d2, d=4)
() {'a': 1, 'b': 2, 'c': 3, 'd': 4}

Examples with invalid arguments (TypeErrors). We're also testing the function
names in the exception messages.

Expand Down
3 changes: 3 additions & 0 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -4321,6 +4321,9 @@ compiler_call_helper(struct compiler *c,
if (!compiler_subkwargs(c, keywords, i - nseen, i)) {
return 0;
}
if (have_dict) {
ADDOP_I(c, DICT_MERGE, 1);
}
have_dict = 1;
nseen = 0;
}
Expand Down