]> granicus.if.org Git - python/commitdiff
Replace Py_NotImplemented returns with the macro form Py_RETURN_NOTIMPLEMENTED.
authorBrian Curtin <brian@python.org>
Thu, 11 Aug 2011 01:28:54 +0000 (20:28 -0500)
committerBrian Curtin <brian@python.org>
Thu, 11 Aug 2011 01:28:54 +0000 (20:28 -0500)
The macro was introduced in #12724.

24 files changed:
Modules/_collectionsmodule.c
Modules/_datetimemodule.c
Modules/_sqlite/row.c
Modules/arraymodule.c
Modules/posixmodule.c
Modules/xxlimited.c
Objects/abstract.c
Objects/bytearrayobject.c
Objects/classobject.c
Objects/codeobject.c
Objects/complexobject.c
Objects/dictobject.c
Objects/floatobject.c
Objects/listobject.c
Objects/longobject.c
Objects/memoryobject.c
Objects/methodobject.c
Objects/object.c
Objects/setobject.c
Objects/sliceobject.c
Objects/tupleobject.c
Objects/typeobject.c
Objects/unicodeobject.c
Objects/weakrefobject.c

index 8743408d8c2aab4901027eecbcf92b83fb1c91a8..156ad1863cd326fb82150ad47bd1cb6c0e38ca98 100644 (file)
@@ -832,8 +832,7 @@ deque_richcompare(PyObject *v, PyObject *w, int op)
 
     if (!PyObject_TypeCheck(v, &deque_type) ||
         !PyObject_TypeCheck(w, &deque_type)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+        Py_RETURN_NOTIMPLEMENTED;
     }
 
     /* Shortcuts */
index 747be45246c9152f4c126bcc0390afba8fa7b733..718dfe2d03a60fb9dc36957798f99078d48110c3 100644 (file)
@@ -1812,8 +1812,7 @@ delta_richcompare(PyObject *self, PyObject *other, int op)
         return diff_to_bool(diff, op);
     }
     else {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+        Py_RETURN_NOTIMPLEMENTED;
     }
 }
 
@@ -1911,10 +1910,8 @@ delta_remainder(PyObject *left, PyObject *right)
     PyObject *pyus_remainder;
     PyObject *remainder;
 
-    if (!PyDelta_Check(left) || !PyDelta_Check(right)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyDelta_Check(left) || !PyDelta_Check(right))
+        Py_RETURN_NOTIMPLEMENTED;
 
     pyus_left = delta_to_microseconds((PyDateTime_Delta *)left);
     if (pyus_left == NULL)
@@ -1949,10 +1946,8 @@ delta_divmod(PyObject *left, PyObject *right)
     PyObject *delta;
     PyObject *result;
 
-    if (!PyDelta_Check(left) || !PyDelta_Check(right)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyDelta_Check(left) || !PyDelta_Check(right))
+        Py_RETURN_NOTIMPLEMENTED;
 
     pyus_left = delta_to_microseconds((PyDateTime_Delta *)left);
     if (pyus_left == NULL)
@@ -2546,10 +2541,9 @@ add_date_timedelta(PyDateTime_Date *date, PyDateTime_Delta *delta, int negate)
 static PyObject *
 date_add(PyObject *left, PyObject *right)
 {
-    if (PyDateTime_Check(left) || PyDateTime_Check(right)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (PyDateTime_Check(left) || PyDateTime_Check(right))
+        Py_RETURN_NOTIMPLEMENTED;
+
     if (PyDate_Check(left)) {
         /* date + ??? */
         if (PyDelta_Check(right))
@@ -2568,17 +2562,15 @@ date_add(PyObject *left, PyObject *right)
                                       (PyDateTime_Delta *) left,
                                       0);
     }
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 static PyObject *
 date_subtract(PyObject *left, PyObject *right)
 {
-    if (PyDateTime_Check(left) || PyDateTime_Check(right)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (PyDateTime_Check(left) || PyDateTime_Check(right))
+        Py_RETURN_NOTIMPLEMENTED;
+
     if (PyDate_Check(left)) {
         if (PyDate_Check(right)) {
             /* date - date */
@@ -2597,8 +2589,7 @@ date_subtract(PyObject *left, PyObject *right)
                                       1);
         }
     }
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 
@@ -2715,10 +2706,8 @@ date_richcompare(PyObject *self, PyObject *other, int op)
                           _PyDateTime_DATE_DATASIZE);
         return diff_to_bool(diff, op);
     }
-    else {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    else
+        Py_RETURN_NOTIMPLEMENTED;
 }
 
 static PyObject *
@@ -3215,10 +3204,8 @@ static PyObject *
 timezone_richcompare(PyDateTime_TimeZone *self,
                      PyDateTime_TimeZone *other, int op)
 {
-    if (op != Py_EQ && op != Py_NE) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (op != Py_EQ && op != Py_NE)
+        Py_RETURN_NOTIMPLEMENTED;
     return delta_richcompare(self->offset, other->offset, op);
 }
 
@@ -3664,10 +3651,8 @@ time_richcompare(PyObject *self, PyObject *other, int op)
     PyObject *offset1, *offset2;
     int diff;
 
-    if (! PyTime_Check(other)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (! PyTime_Check(other))
+        Py_RETURN_NOTIMPLEMENTED;
 
     if (GET_TIME_TZINFO(self) == GET_TIME_TZINFO(other)) {
         diff = memcmp(((PyDateTime_Time *)self)->data,
@@ -4356,8 +4341,7 @@ datetime_add(PyObject *left, PyObject *right)
                                       (PyDateTime_Delta *) left,
                                       1);
     }
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 static PyObject *
@@ -4559,8 +4543,7 @@ datetime_richcompare(PyObject *self, PyObject *other, int op)
                 Py_RETURN_TRUE;
             return cmperror(self, other);
         }
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+        Py_RETURN_NOTIMPLEMENTED;
     }
 
     if (GET_DT_TZINFO(self) == GET_DT_TZINFO(other)) {
index 3d440942f9d5e922a4cef4b43a02c196fd94a0a6..b50658c220dbc79c6d8455587ccbbf960ff0eb79 100644 (file)
@@ -173,10 +173,9 @@ static Py_hash_t pysqlite_row_hash(pysqlite_Row *self)
 
 static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other, int opid)
 {
-    if (opid != Py_EQ && opid != Py_NE) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (opid != Py_EQ && opid != Py_NE)
+        Py_RETURN_NOTIMPLEMENTED;
+
     if (PyType_IsSubtype(Py_TYPE(_other), &pysqlite_RowType)) {
         pysqlite_Row *other = (pysqlite_Row *)_other;
         PyObject *res = PyObject_RichCompare(self->description, other->description, opid);
@@ -186,8 +185,7 @@ static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other,
             return PyObject_RichCompare(self->data, other->data, opid);
         }
     }
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 PyMappingMethods pysqlite_row_as_mapping = {
index ae68c15e7752dcbb7b5336c2ef67016ec9e9dda2..81c9c363d36b4a89b6108b1b56ca68be11e258e5 100644 (file)
@@ -514,10 +514,8 @@ array_richcompare(PyObject *v, PyObject *w, int op)
     Py_ssize_t i, k;
     PyObject *res;
 
-    if (!array_Check(v) || !array_Check(w)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!array_Check(v) || !array_Check(w))
+        Py_RETURN_NOTIMPLEMENTED;
 
     va = (arrayobject *)v;
     wa = (arrayobject *)w;
index 2be5ec9297c9b0f58388f177f8c36caad1024275..d701690a5d0fd5fffc70b16109a9ffa4d66b42d4 100644 (file)
@@ -4925,10 +4925,9 @@ cpu_set_richcompare(Py_cpu_set *set, Py_cpu_set *other, int op)
 {
     int eq;
 
-    if ((op != Py_EQ && op != Py_NE) || Py_TYPE(other) != &cpu_set_type) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if ((op != Py_EQ && op != Py_NE) || Py_TYPE(other) != &cpu_set_type)
+        Py_RETURN_NOTIMPLEMENTED;
+
     eq = set->ncpus == other->ncpus && CPU_EQUAL_S(set->size, set->set, other->set);
     if ((op == Py_EQ) ? eq : !eq)
         Py_RETURN_TRUE;
@@ -4949,8 +4948,7 @@ cpu_set_richcompare(Py_cpu_set *set, Py_cpu_set *other, int op)
         } \
         if (Py_TYPE(right) != &cpu_set_type || left->ncpus != right->ncpus) { \
             Py_DECREF(res); \
-            Py_INCREF(Py_NotImplemented); \
-            return Py_NotImplemented; \
+            Py_RETURN_NOTIMPLEMENTED; \
         } \
         assert(left->size == right->size && right->size == res->size); \
         op(res->size, res->set, left->set, right->set); \
index ec924f2117bd78a73f21980969579a5b854b87fa..661b6e294af363d1b2c7ac8e49c9ba141f7c53e0 100644 (file)
@@ -187,8 +187,7 @@ static PyType_Spec Str_Type_spec = {
 static PyObject *
 null_richcompare(PyObject *self, PyObject *other, int op)
 {
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 static PyType_Slot Null_Type_slots[] = {
index f992573d332eb225287b9bb661c747d6ea7495a0..8298fd4f5419f7ee391e3231a759448a2d02c8b0 100644 (file)
@@ -793,8 +793,7 @@ binary_op1(PyObject *v, PyObject *w, const int op_slot)
             return x;
         Py_DECREF(x); /* can't do it */
     }
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 static PyObject *
index 37668c7432c30e280775d85159de96d2b8b429a1..d365fbc20ab8df83f3427b64d75cf291456acf74 100644 (file)
@@ -964,23 +964,20 @@ bytearray_richcompare(PyObject *self, PyObject *other, int op)
                 return NULL;
         }
 
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+        Py_RETURN_NOTIMPLEMENTED;
     }
 
     self_size = _getbuffer(self, &self_bytes);
     if (self_size < 0) {
         PyErr_Clear();
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+        Py_RETURN_NOTIMPLEMENTED;
     }
 
     other_size = _getbuffer(other, &other_bytes);
     if (other_size < 0) {
         PyErr_Clear();
         PyBuffer_Release(&self_bytes);
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+        Py_RETURN_NOTIMPLEMENTED;
     }
 
     if (self_size != other_size && (op == Py_EQ || op == Py_NE)) {
index 6df930fdcf629b35aa2f54b7d181927114d0476e..b52a209e91ec56697fd39f412592b5de605ea2f0 100644 (file)
@@ -190,8 +190,7 @@ method_richcompare(PyObject *self, PyObject *other, int op)
         !PyMethod_Check(self) ||
         !PyMethod_Check(other))
     {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+        Py_RETURN_NOTIMPLEMENTED;
     }
     a = (PyMethodObject *)self;
     b = (PyMethodObject *)other;
@@ -516,8 +515,7 @@ instancemethod_richcompare(PyObject *self, PyObject *other, int op)
         !PyInstanceMethod_Check(self) ||
         !PyInstanceMethod_Check(other))
     {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+        Py_RETURN_NOTIMPLEMENTED;
     }
     a = (PyInstanceMethodObject *)self;
     b = (PyInstanceMethodObject *)other;
index db5c17ecb8ac2ee3938580491d40cf3266a0e65b..3f77718f2cfa9273ad7302523a43390407caff25 100644 (file)
@@ -402,8 +402,7 @@ code_richcompare(PyObject *self, PyObject *other, int op)
     if ((op != Py_EQ && op != Py_NE) ||
         !PyCode_Check(self) ||
         !PyCode_Check(other)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+        Py_RETURN_NOTIMPLEMENTED;
     }
 
     co = (PyCodeObject *)self;
index 3c6c32ae104ed02e01cc7b2f81cba8690cb694db..85c1d229193a1c6ddcf490b6b9daf7feede1f878 100644 (file)
@@ -650,8 +650,7 @@ complex_richcompare(PyObject *v, PyObject *w, int op)
     return res;
 
 Unimplemented:
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 static PyObject *
index 3fa5cc4b95bbe1274ee8e3b613858c6a64644884..cdc27abc07ad329758f036650f5088ddc3ea4c91 100644 (file)
@@ -2608,10 +2608,8 @@ dictview_richcompare(PyObject *self, PyObject *other, int op)
     assert(PyDictViewSet_Check(self));
     assert(other != NULL);
 
-    if (!PyAnySet_Check(other) && !PyDictViewSet_Check(other)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyAnySet_Check(other) && !PyDictViewSet_Check(other))
+        Py_RETURN_NOTIMPLEMENTED;
 
     len_self = PyObject_Size(self);
     if (len_self < 0)
index 33926148c0aaf59440448839920a37662d8a9113..a031d1b63bcfd10e26ee9f416a3b0eb042f1e986 100644 (file)
@@ -517,8 +517,7 @@ float_richcompare(PyObject *v, PyObject *w, int op)
     return PyBool_FromLong(r);
 
  Unimplemented:
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 static Py_hash_t
index dab91db2a146387ad90d1bfbccaa254e7018976e..2cd8642b74e3cfd1f8db2b727a5dd0177b54ea63 100644 (file)
@@ -2225,10 +2225,8 @@ list_richcompare(PyObject *v, PyObject *w, int op)
     PyListObject *vl, *wl;
     Py_ssize_t i;
 
-    if (!PyList_Check(v) || !PyList_Check(w)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyList_Check(v) || !PyList_Check(w))
+        Py_RETURN_NOTIMPLEMENTED;
 
     vl = (PyListObject *)v;
     wl = (PyListObject *)w;
index 552f8f0b898c1e0792a8ae0ea0bb7566e6b91f58..5df519cfdbc981fde0076024fcba0c483920d906 100644 (file)
@@ -1382,10 +1382,8 @@ PyLong_AsLongLongAndOverflow(PyObject *vv, int *overflow)
 
 #define CHECK_BINOP(v,w)                                \
     do {                                                \
-        if (!PyLong_Check(v) || !PyLong_Check(w)) {     \
-            Py_INCREF(Py_NotImplemented);               \
-            return Py_NotImplemented;                   \
-        }                                               \
+        if (!PyLong_Check(v) || !PyLong_Check(w))       \
+            Py_RETURN_NOTIMPLEMENTED;                   \
     } while(0)
 
 /* bits_in_digit(d) returns the unique integer k such that 2**(k-1) <= d <
@@ -3611,8 +3609,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
     else {
         Py_DECREF(a);
         Py_DECREF(b);
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+        Py_RETURN_NOTIMPLEMENTED;
     }
 
     if (Py_SIZE(b) < 0) {  /* if exponent is negative */
index 2e32b2a0e9f51c560b2f2b7d2d2cf8e758867109..e0d1a898b30ee8c0dd7f1f1eaf282fafa74ab91a 100644 (file)
@@ -773,8 +773,7 @@ _end:
 _notimpl:
     PyBuffer_Release(&vv);
     PyBuffer_Release(&ww);
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 
index f1a9f4b7022d07aa118a759ddb5dd7f4d53bf7d8..a7334cfe8856b569b54a1c5e6470948b07a8a0eb 100644 (file)
@@ -208,8 +208,7 @@ meth_richcompare(PyObject *self, PyObject *other, int op)
         !PyCFunction_Check(self) ||
         !PyCFunction_Check(other))
     {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+        Py_RETURN_NOTIMPLEMENTED;
     }
     a = (PyCFunctionObject *)self;
     b = (PyCFunctionObject *)other;
index 6af426f75c1f5ce4287c3e07fca052e91f15f347..cf49e1b4eaf4ad4a7dfae7c95efebc41838e9b36 100644 (file)
@@ -1392,8 +1392,7 @@ notimplemented_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
         PyErr_SetString(PyExc_TypeError, "NotImplementedType takes no arguments");
         return NULL;
     }
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 static PyTypeObject PyNotImplemented_Type = {
index 2e6251884c5d4bde46ecaea91532a5718e026b31..d1bad27d56ea4e903a63be56f8199002bec8373d 100644 (file)
@@ -1212,10 +1212,8 @@ set_or(PySetObject *so, PyObject *other)
 {
     PySetObject *result;
 
-    if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
+        Py_RETURN_NOTIMPLEMENTED;
 
     result = (PySetObject *)set_copy(so);
     if (result == NULL)
@@ -1232,10 +1230,9 @@ set_or(PySetObject *so, PyObject *other)
 static PyObject *
 set_ior(PySetObject *so, PyObject *other)
 {
-    if (!PyAnySet_Check(other)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyAnySet_Check(other))
+        Py_RETURN_NOTIMPLEMENTED;
+
     if (set_update_internal(so, other) == -1)
         return NULL;
     Py_INCREF(so);
@@ -1385,10 +1382,8 @@ PyDoc_STRVAR(intersection_update_doc,
 static PyObject *
 set_and(PySetObject *so, PyObject *other)
 {
-    if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
+        Py_RETURN_NOTIMPLEMENTED;
     return set_intersection(so, other);
 }
 
@@ -1397,10 +1392,8 @@ set_iand(PySetObject *so, PyObject *other)
 {
     PyObject *result;
 
-    if (!PyAnySet_Check(other)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyAnySet_Check(other))
+        Py_RETURN_NOTIMPLEMENTED;
     result = set_intersection_update(so, other);
     if (result == NULL)
         return NULL;
@@ -1627,20 +1620,16 @@ PyDoc_STRVAR(difference_doc,
 static PyObject *
 set_sub(PySetObject *so, PyObject *other)
 {
-    if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
+        Py_RETURN_NOTIMPLEMENTED;
     return set_difference(so, other);
 }
 
 static PyObject *
 set_isub(PySetObject *so, PyObject *other)
 {
-    if (!PyAnySet_Check(other)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyAnySet_Check(other))
+        Py_RETURN_NOTIMPLEMENTED;
     if (set_difference_update_internal(so, other) == -1)
         return NULL;
     Py_INCREF(so);
@@ -1738,10 +1727,8 @@ PyDoc_STRVAR(symmetric_difference_doc,
 static PyObject *
 set_xor(PySetObject *so, PyObject *other)
 {
-    if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
+        Py_RETURN_NOTIMPLEMENTED;
     return set_symmetric_difference(so, other);
 }
 
@@ -1750,10 +1737,8 @@ set_ixor(PySetObject *so, PyObject *other)
 {
     PyObject *result;
 
-    if (!PyAnySet_Check(other)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyAnySet_Check(other))
+        Py_RETURN_NOTIMPLEMENTED;
     result = set_symmetric_difference_update(so, other);
     if (result == NULL)
         return NULL;
@@ -1815,10 +1800,9 @@ set_richcompare(PySetObject *v, PyObject *w, int op)
 {
     PyObject *r1, *r2;
 
-    if(!PyAnySet_Check(w)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if(!PyAnySet_Check(w))
+        Py_RETURN_NOTIMPLEMENTED;
+
     switch (op) {
     case Py_EQ:
         if (PySet_GET_SIZE(v) != PySet_GET_SIZE(w))
@@ -1848,8 +1832,7 @@ set_richcompare(PySetObject *v, PyObject *w, int op)
             Py_RETURN_FALSE;
         return set_issuperset(v, w);
     }
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 static PyObject *
index 53cc951a735cee904f98fdc56c88baffaecbe049..92464abf7ce304c9faa842a2b1ec4f5ce410b754 100644 (file)
@@ -326,10 +326,8 @@ slice_richcompare(PyObject *v, PyObject *w, int op)
     PyObject *t2;
     PyObject *res;
 
-    if (!PySlice_Check(v) || !PySlice_Check(w)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PySlice_Check(v) || !PySlice_Check(w))
+        Py_RETURN_NOTIMPLEMENTED;
 
     if (v == w) {
         /* XXX Do we really need this shortcut?
index bfb7ec74b31c05fe2d30d0eca9f4ef3c68e3bdb9..ccfd281fbb2655c0fd5202ad5871897567860077 100644 (file)
@@ -546,10 +546,8 @@ tuplerichcompare(PyObject *v, PyObject *w, int op)
     Py_ssize_t i;
     Py_ssize_t vlen, wlen;
 
-    if (!PyTuple_Check(v) || !PyTuple_Check(w)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyTuple_Check(v) || !PyTuple_Check(w))
+        Py_RETURN_NOTIMPLEMENTED;
 
     vt = (PyTupleObject *)v;
     wt = (PyTupleObject *)w;
index d80b594e9a6d7b444841c928ed5abc7c52575beb..bb4622f73805709e34d4697c48874e0c2d067675 100644 (file)
@@ -1212,10 +1212,8 @@ call_maybe(PyObject *o, char *name, PyObject **nameobj, char *format, ...)
     func = lookup_maybe(o, name, nameobj);
     if (func == NULL) {
         va_end(va);
-        if (!PyErr_Occurred()) {
-            Py_INCREF(Py_NotImplemented);
-            return Py_NotImplemented;
-        }
+        if (!PyErr_Occurred())
+            Py_RETURN_NOTIMPLEMENTED;
         return NULL;
     }
 
@@ -3449,8 +3447,7 @@ object_reduce_ex(PyObject *self, PyObject *args)
 static PyObject *
 object_subclasshook(PyObject *cls, PyObject *args)
 {
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 PyDoc_STRVAR(object_subclasshook_doc,
@@ -4818,8 +4815,7 @@ FUNCNAME(PyObject *self, PyObject *other) \
         return call_maybe( \
             other, ROPSTR, &rcache_str, "(O)", self); \
     } \
-    Py_INCREF(Py_NotImplemented); \
-    return Py_NotImplemented; \
+    Py_RETURN_NOTIMPLEMENTED; \
 }
 
 #define SLOT1BIN(FUNCNAME, SLOTNAME, OPSTR, ROPSTR) \
@@ -4996,8 +4992,7 @@ slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus)
         return call_method(self, "__pow__", &pow_str,
                            "(OO)", other, modulus);
     }
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 SLOT0(slot_nb_negative, "__neg__")
@@ -5320,8 +5315,7 @@ slot_tp_richcompare(PyObject *self, PyObject *other, int op)
     func = lookup_method(self, name_op[op], &op_str[op]);
     if (func == NULL) {
         PyErr_Clear();
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+        Py_RETURN_NOTIMPLEMENTED;
     }
     args = PyTuple_Pack(1, other);
     if (args == NULL)
index bef2abfac17029ffd8f689a8c08650eaaff3547b..0918671ec0a9619dd82062cfbe175034265ddf94 100644 (file)
@@ -7417,8 +7417,7 @@ PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)
         return v;
     }
 
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
+    Py_RETURN_NOTIMPLEMENTED;
 }
 
 int
@@ -9291,10 +9290,8 @@ static PyMethodDef unicode_methods[] = {
 static PyObject *
 unicode_mod(PyObject *v, PyObject *w)
 {
-    if (!PyUnicode_Check(v)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
+    if (!PyUnicode_Check(v))
+        Py_RETURN_NOTIMPLEMENTED;
     return PyUnicode_Format(v, w);
 }
 
index d0a09d5b0edd0eb4756d94cc7cc4098b46a8d19b..c99f6ba1b6f125330c757e2dd94276a31d5012a2 100644 (file)
@@ -193,8 +193,7 @@ weakref_richcompare(PyWeakReference* self, PyWeakReference* other, int op)
     if ((op != Py_EQ && op != Py_NE) ||
         !PyWeakref_Check(self) ||
         !PyWeakref_Check(other)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
+        Py_RETURN_NOTIMPLEMENTED;
     }
     if (PyWeakref_GET_OBJECT(self) == Py_None
         || PyWeakref_GET_OBJECT(other) == Py_None) {