Skip to content

Commit 410b730

Browse files
Make sure that keyword arguments are merged into the arguments dictionary when dict unpacking and keyword arguments are interleaved. (GH-20553) (GH-20569)
(cherry picked from commit db64f12) Co-authored-by: Mark Shannon <[email protected]>
1 parent a169961 commit 410b730

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Lib/test/test_extcall.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@
7979
>>> f(1, 2, 3, *(4, 5), x=6, y=7, **UserDict(a=8, b=9))
8080
(1, 2, 3, 4, 5) {'a': 8, 'b': 9, 'x': 6, 'y': 7}
8181
82+
Mix keyword arguments and dict unpacking
83+
84+
>>> d1 = {'a':1}
85+
86+
>>> d2 = {'c':3}
87+
88+
>>> f(b=2, **d1, **d2)
89+
() {'a': 1, 'b': 2, 'c': 3}
90+
91+
>>> f(**d1, b=2, **d2)
92+
() {'a': 1, 'b': 2, 'c': 3}
93+
94+
>>> f(**d1, **d2, b=2)
95+
() {'a': 1, 'b': 2, 'c': 3}
96+
97+
>>> f(**d1, b=2, **d2, d=4)
98+
() {'a': 1, 'b': 2, 'c': 3, 'd': 4}
99+
82100
Examples with invalid arguments (TypeErrors). We're also testing the function
83101
names in the exception messages.
84102

Python/compile.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4321,6 +4321,9 @@ compiler_call_helper(struct compiler *c,
43214321
if (!compiler_subkwargs(c, keywords, i - nseen, i)) {
43224322
return 0;
43234323
}
4324+
if (have_dict) {
4325+
ADDOP_I(c, DICT_MERGE, 1);
4326+
}
43244327
have_dict = 1;
43254328
nseen = 0;
43264329
}

0 commit comments

Comments
 (0)