diff --git a/Python/ceval.c b/Python/ceval.c index 38ac509..ad22dad 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2686,6 +2686,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) int num_maps; int function_location; int i; + Py_ssize_t endsize = 0; PyObject *sum = PyDict_New(); if (sum == NULL) goto error; @@ -2699,50 +2700,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) for (i = num_maps; i > 0; i--) { PyObject *arg = PEEK(i); - if (with_call) { - PyObject *intersection = _PyDictView_Intersect(sum, arg); - - if (intersection == NULL) { - if (PyErr_ExceptionMatches(PyExc_AttributeError)) { - PyObject *func = ( - PEEK(function_location + num_maps)); - PyErr_Format(PyExc_TypeError, - "%.200s%.200s argument after ** " - "must be a mapping, not %.200s", - PyEval_GetFuncName(func), - PyEval_GetFuncDesc(func), - arg->ob_type->tp_name); - } - Py_DECREF(sum); - goto error; - } - - if (PySet_GET_SIZE(intersection)) { - Py_ssize_t idx = 0; - PyObject *key; - PyObject *func = PEEK(function_location + num_maps); - Py_hash_t hash; - _PySet_NextEntry(intersection, &idx, &key, &hash); - if (!PyUnicode_Check(key)) { - PyErr_Format(PyExc_TypeError, - "%.200s%.200s keywords must be strings", - PyEval_GetFuncName(func), - PyEval_GetFuncDesc(func)); - } else { - PyErr_Format(PyExc_TypeError, - "%.200s%.200s got multiple " - "values for keyword argument '%U'", - PyEval_GetFuncName(func), - PyEval_GetFuncDesc(func), - key); - } - Py_DECREF(intersection); - Py_DECREF(sum); - goto error; - } - Py_DECREF(intersection); - } - if (PyDict_Update(sum, arg) < 0) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Format(PyExc_TypeError, @@ -2752,6 +2709,47 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) Py_DECREF(sum); goto error; } + if (with_call) + { + endsize += PyDict_Size(arg); + if (endsize != PyDict_Size(sum)) + { + for (Py_ssize_t j = num_maps; j > i; j--) { + PyObject *jth = PEEK(j); + PyObject *intersection = _PyDictView_Intersect(arg, jth); + if (intersection == NULL) { + Py_DECREF(sum); + goto error; + } + + if (PySet_GET_SIZE(intersection)) { + Py_ssize_t idx = 0; + PyObject *key; + PyObject *func = PEEK(function_location + num_maps); + Py_hash_t hash; + _PySet_NextEntry(intersection, &idx, &key, &hash); + if (!PyUnicode_Check(key)) { + PyErr_Format(PyExc_TypeError, + "%.200s%.200s keywords must be strings", + PyEval_GetFuncName(func), + PyEval_GetFuncDesc(func)); + } else { + PyErr_Format(PyExc_TypeError, + "%.200s%.200s got multiple " + "values for keyword argument '%U'", + PyEval_GetFuncName(func), + PyEval_GetFuncDesc(func), + key); + } + Py_DECREF(intersection); + Py_DECREF(sum); + goto error; + } + Py_DECREF(intersection); + + } + } + } } while (num_maps--)