]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Make sure that keyword arguments are merged into the arguments dictionary when dict...
authorMark Shannon <mark@hotpy.org>
Mon, 1 Jun 2020 09:42:42 +0000 (10:42 +0100)
committerGitHub <noreply@github.com>
Mon, 1 Jun 2020 09:42:42 +0000 (10:42 +0100)
Lib/test/test_extcall.py
Python/compile.c

index 1faf29e01d3ca7baea4ad9ec9850c7a189c222e6..4205ca82222f274c5238217fa30aab2204c28e88 100644 (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))
     (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.
 
index 4a587c00fd4021d0c915d58622b5e9b4cf8c5084..fccc688affca6836923df95ddde7762744b10048 100644 (file)
@@ -4321,6 +4321,9 @@ ex_call:
                     if (!compiler_subkwargs(c, keywords, i - nseen, i)) {
                         return 0;
                     }
+                    if (have_dict) {
+                        ADDOP_I(c, DICT_MERGE, 1);
+                    }
                     have_dict = 1;
                     nseen = 0;
                 }