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

Mark Shannon webhook-mailer at python.org
Mon Jun 1 05:42:59 EDT 2020


https://github.com/python/cpython/commit/db64f12e4deda2abbafb6d2bd5c06762fca991ff
commit: db64f12e4deda2abbafb6d2bd5c06762fca991ff
branch: master
author: Mark Shannon <mark at hotpy.org>
committer: GitHub <noreply at github.com>
date: 2020-06-01T10:42:42+01:00
summary:

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

files:
M Lib/test/test_extcall.py
M Python/compile.c

diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py
index 1faf29e01d3ca..4205ca82222f2 100644
--- a/Lib/test/test_extcall.py
+++ b/Lib/test/test_extcall.py
@@ -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.
 
diff --git a/Python/compile.c b/Python/compile.c
index 4a587c00fd402..fccc688affca6 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -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;
                 }



More information about the Python-checkins mailing list