diff -r 2cb530243943 Lib/test/test_extcall.py --- a/Lib/test/test_extcall.py Fri Feb 10 00:14:55 2017 -0800 +++ b/Lib/test/test_extcall.py Sun Feb 12 16:21:04 2017 +0200 @@ -52,15 +52,15 @@ Here we add keyword arguments >>> f(1, 2, **{'a': -1, 'b': 5}, **{'a': 4, 'c': 6}) Traceback (most recent call last): ... - TypeError: f() got multiple values for keyword argument 'a' + TypeError: function got multiple values for keyword argument 'a' >>> f(1, 2, **{'a': -1, 'b': 5}, a=4, c=6) Traceback (most recent call last): ... - TypeError: f() got multiple values for keyword argument 'a' + TypeError: function got multiple values for keyword argument 'a' >>> f(1, 2, a=3, **{'a': 4}, **{'a': 5}) Traceback (most recent call last): ... - TypeError: f() got multiple values for keyword argument 'a' + TypeError: function got multiple values for keyword argument 'a' >>> f(1, 2, 3, *[4, 5], **{'a':6, 'b':7}) (1, 2, 3, 4, 5) {'a': 6, 'b': 7} >>> f(1, 2, 3, x=4, y=5, *(6, 7), **{'a':8, 'b': 9}) diff -r 2cb530243943 Python/ceval.c --- a/Python/ceval.c Fri Feb 10 00:14:55 2017 -0800 +++ b/Python/ceval.c Sun Feb 12 16:21:04 2017 +0200 @@ -2666,14 +2666,22 @@ PyEval_EvalFrameEx(PyFrameObject *f, int if (PyErr_ExceptionMatches(PyExc_AttributeError) || !PyMapping_Check(arg)) { int function_location = (oparg>>8) & 0xff; - 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); + if (function_location == 1) { + 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); + } + else { + PyErr_Format(PyExc_TypeError, + "argument after ** " + "must be a mapping, not %.200s", + arg->ob_type->tp_name); + } } Py_DECREF(sum); goto error; @@ -2683,21 +2691,34 @@ PyEval_EvalFrameEx(PyFrameObject *f, int Py_ssize_t idx = 0; PyObject *key; int function_location = (oparg>>8) & 0xff; - 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); + if (function_location == 1) { + PyObject *func = PEEK(function_location + num_maps); + 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); + } + } + else { + if (!PyUnicode_Check(key)) { + PyErr_SetString(PyExc_TypeError, + "keywords must be strings"); + } else { + PyErr_Format(PyExc_TypeError, + "function got multiple " + "values for keyword argument '%U'", + key); + } } Py_DECREF(intersection); Py_DECREF(sum); @@ -2710,13 +2731,21 @@ PyEval_EvalFrameEx(PyFrameObject *f, int if (PyErr_ExceptionMatches(PyExc_AttributeError)) { if (with_call) { int function_location = (oparg>>8) & 0xff; - 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); + if (function_location == 1) { + 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); + } + else { + PyErr_Format(PyExc_TypeError, + "argument after ** " + "must be a mapping, not %.200s", + arg->ob_type->tp_name); + } } else { PyErr_Format(PyExc_TypeError,