mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-136327: Fix inconsistent `TypeError` messages regarding invalid values after * and ** (#136395)
This commit is contained in:
parent
b3c713a0af
commit
4f8e7b5ac5
4 changed files with 23 additions and 36 deletions
|
|
@ -3272,17 +3272,9 @@ int
|
|||
_Py_Check_ArgsIterable(PyThreadState *tstate, PyObject *func, PyObject *args)
|
||||
{
|
||||
if (Py_TYPE(args)->tp_iter == NULL && !PySequence_Check(args)) {
|
||||
/* _Py_Check_ArgsIterable() may be called with a live exception:
|
||||
* clear it to prevent calling _PyObject_FunctionStr() with an
|
||||
* exception set. */
|
||||
_PyErr_Clear(tstate);
|
||||
PyObject *funcstr = _PyObject_FunctionStr(func);
|
||||
if (funcstr != NULL) {
|
||||
_PyErr_Format(tstate, PyExc_TypeError,
|
||||
"%U argument after * must be an iterable, not %.200s",
|
||||
funcstr, Py_TYPE(args)->tp_name);
|
||||
Py_DECREF(funcstr);
|
||||
}
|
||||
_PyErr_Format(tstate, PyExc_TypeError,
|
||||
"Value after * must be an iterable, not %.200s",
|
||||
Py_TYPE(args)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -3298,15 +3290,10 @@ _PyEval_FormatKwargsError(PyThreadState *tstate, PyObject *func, PyObject *kwarg
|
|||
* is not a mapping.
|
||||
*/
|
||||
if (_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)) {
|
||||
_PyErr_Clear(tstate);
|
||||
PyObject *funcstr = _PyObject_FunctionStr(func);
|
||||
if (funcstr != NULL) {
|
||||
_PyErr_Format(
|
||||
tstate, PyExc_TypeError,
|
||||
"%U argument after ** must be a mapping, not %.200s",
|
||||
funcstr, Py_TYPE(kwargs)->tp_name);
|
||||
Py_DECREF(funcstr);
|
||||
}
|
||||
_PyErr_Format(
|
||||
tstate, PyExc_TypeError,
|
||||
"Value after ** must be a mapping, not %.200s",
|
||||
Py_TYPE(kwargs)->tp_name);
|
||||
}
|
||||
else if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
|
||||
PyObject *exc = _PyErr_GetRaisedException(tstate);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue