]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport jhylton's checkin of
authorMichael W. Hudson <mwh@python.net>
Mon, 11 Mar 2002 10:11:46 +0000 (10:11 +0000)
committerMichael W. Hudson <mwh@python.net>
Mon, 11 Mar 2002 10:11:46 +0000 (10:11 +0000)
    revision 2.97 of abstract.c

Fix for SF bug 516727: MyInt(2) + "3" -> NotImplemented

PyNumber_Add() tries the nb_add slot first, then falls back to
sq_concat.  However, it didn't check the return value of sq_concat.
If sq_concat returns NotImplemented, raise the standard TypeError.

Objects/abstract.c

index 2acfd0865cecec9b75e025dfd04f2adc97c8d65a..2207602550ce98f6ea3f8b04ce2cc166940bd157 100644 (file)
@@ -605,11 +605,10 @@ PyNumber_Add(PyObject *v, PyObject *w)
        PyObject *result = binary_op1(v, w, NB_SLOT(nb_add));
        if (result == Py_NotImplemented) {
                PySequenceMethods *m = v->ob_type->tp_as_sequence;
-               Py_DECREF(Py_NotImplemented);
-               if (m && m->sq_concat) {
+               Py_DECREF(result);
+               if (m && m->sq_concat)
                        result = (*m->sq_concat)(v, w);
-               }
-                else {
+               if (result == Py_NotImplemented) {
                     PyErr_Format(
                            PyExc_TypeError,
                            "unsupported operand types for +: '%s' and '%s'",