Make sure that keyword arguments are merged into the arguments dictionary when dict unpacking and keyword arguments are interleaved. (GH-20553)

This commit is contained in:
Mark Shannon 2020-06-01 10:42:42 +01:00 committed by GitHub
parent a871f692b4
commit db64f12e4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -79,6 +79,24 @@ Here we add keyword arguments
>>> f(1, 2, 3, *(4, 5), x=6, y=7, **UserDict(a=8, b=9)) >>> 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} (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 Examples with invalid arguments (TypeErrors). We're also testing the function
names in the exception messages. names in the exception messages.

View File

@ -4321,6 +4321,9 @@ ex_call:
if (!compiler_subkwargs(c, keywords, i - nseen, i)) { if (!compiler_subkwargs(c, keywords, i - nseen, i)) {
return 0; return 0;
} }
if (have_dict) {
ADDOP_I(c, DICT_MERGE, 1);
}
have_dict = 1; have_dict = 1;
nseen = 0; nseen = 0;
} }