diff options
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 6 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 3f790e8824..ddfc730565 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -5092,6 +5092,7 @@ slot_nb_nonzero(PyObject *self) PyObject *func, *args; static PyObject *nonzero_str, *len_str; int result = -1; + int using_len = 0; func = lookup_maybe(self, "__nonzero__", &nonzero_str); if (func == NULL) { @@ -5100,6 +5101,7 @@ slot_nb_nonzero(PyObject *self) func = lookup_maybe(self, "__len__", &len_str); if (func == NULL) return PyErr_Occurred() ? -1 : 1; + using_len = 1; } args = PyTuple_New(0); if (args != NULL) { @@ -5110,8 +5112,10 @@ slot_nb_nonzero(PyObject *self) result = PyObject_IsTrue(temp); else { PyErr_Format(PyExc_TypeError, - "__nonzero__ should return " + "%s should return " "bool or int, returned %s", + (using_len ? "__len__" + : "__nonzero__"), temp->ob_type->tp_name); result = -1; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index acec713f16..5c27b048dc 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1385,7 +1385,7 @@ int unicode_decode_call_errorhandler(const char *errors, PyObject **errorHandler if (restuple == NULL) goto onError; if (!PyTuple_Check(restuple)) { - PyErr_Format(PyExc_TypeError, &argparse[4]); + PyErr_SetString(PyExc_TypeError, &argparse[4]); goto onError; } if (!PyArg_ParseTuple(restuple, argparse, &PyUnicode_Type, &repunicode, &newpos)) @@ -3440,7 +3440,7 @@ static PyObject *unicode_encode_call_errorhandler(const char *errors, if (restuple == NULL) return NULL; if (!PyTuple_Check(restuple)) { - PyErr_Format(PyExc_TypeError, &argparse[4]); + PyErr_SetString(PyExc_TypeError, &argparse[4]); Py_DECREF(restuple); return NULL; } @@ -4712,7 +4712,7 @@ static PyObject *unicode_translate_call_errorhandler(const char *errors, if (restuple == NULL) return NULL; if (!PyTuple_Check(restuple)) { - PyErr_Format(PyExc_TypeError, &argparse[4]); + PyErr_SetString(PyExc_TypeError, &argparse[4]); Py_DECREF(restuple); return NULL; } |