Replace Py_NotImplemented returns with the macro form Py_RETURN_NOTIMPLEMENTED.

The macro was introduced in #12724.
This commit is contained in:
Brian Curtin 2011-08-10 20:28:54 -05:00
parent 7d2f9e1342
commit dfc80e3d97
24 changed files with 87 additions and 162 deletions

View File

@ -832,8 +832,7 @@ deque_richcompare(PyObject *v, PyObject *w, int op)
if (!PyObject_TypeCheck(v, &deque_type) || if (!PyObject_TypeCheck(v, &deque_type) ||
!PyObject_TypeCheck(w, &deque_type)) { !PyObject_TypeCheck(w, &deque_type)) {
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
/* Shortcuts */ /* Shortcuts */

View File

@ -1812,8 +1812,7 @@ delta_richcompare(PyObject *self, PyObject *other, int op)
return diff_to_bool(diff, op); return diff_to_bool(diff, op);
} }
else { else {
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
} }
@ -1911,10 +1910,8 @@ delta_remainder(PyObject *left, PyObject *right)
PyObject *pyus_remainder; PyObject *pyus_remainder;
PyObject *remainder; PyObject *remainder;
if (!PyDelta_Check(left) || !PyDelta_Check(right)) { if (!PyDelta_Check(left) || !PyDelta_Check(right))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
pyus_left = delta_to_microseconds((PyDateTime_Delta *)left); pyus_left = delta_to_microseconds((PyDateTime_Delta *)left);
if (pyus_left == NULL) if (pyus_left == NULL)
@ -1949,10 +1946,8 @@ delta_divmod(PyObject *left, PyObject *right)
PyObject *delta; PyObject *delta;
PyObject *result; PyObject *result;
if (!PyDelta_Check(left) || !PyDelta_Check(right)) { if (!PyDelta_Check(left) || !PyDelta_Check(right))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
pyus_left = delta_to_microseconds((PyDateTime_Delta *)left); pyus_left = delta_to_microseconds((PyDateTime_Delta *)left);
if (pyus_left == NULL) if (pyus_left == NULL)
@ -2546,10 +2541,9 @@ add_date_timedelta(PyDateTime_Date *date, PyDateTime_Delta *delta, int negate)
static PyObject * static PyObject *
date_add(PyObject *left, PyObject *right) date_add(PyObject *left, PyObject *right)
{ {
if (PyDateTime_Check(left) || PyDateTime_Check(right)) { if (PyDateTime_Check(left) || PyDateTime_Check(right))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
if (PyDate_Check(left)) { if (PyDate_Check(left)) {
/* date + ??? */ /* date + ??? */
if (PyDelta_Check(right)) if (PyDelta_Check(right))
@ -2568,17 +2562,15 @@ date_add(PyObject *left, PyObject *right)
(PyDateTime_Delta *) left, (PyDateTime_Delta *) left,
0); 0);
} }
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
static PyObject * static PyObject *
date_subtract(PyObject *left, PyObject *right) date_subtract(PyObject *left, PyObject *right)
{ {
if (PyDateTime_Check(left) || PyDateTime_Check(right)) { if (PyDateTime_Check(left) || PyDateTime_Check(right))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
if (PyDate_Check(left)) { if (PyDate_Check(left)) {
if (PyDate_Check(right)) { if (PyDate_Check(right)) {
/* date - date */ /* date - date */
@ -2597,8 +2589,7 @@ date_subtract(PyObject *left, PyObject *right)
1); 1);
} }
} }
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
@ -2715,10 +2706,8 @@ date_richcompare(PyObject *self, PyObject *other, int op)
_PyDateTime_DATE_DATASIZE); _PyDateTime_DATE_DATASIZE);
return diff_to_bool(diff, op); return diff_to_bool(diff, op);
} }
else { else
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
} }
static PyObject * static PyObject *
@ -3215,10 +3204,8 @@ static PyObject *
timezone_richcompare(PyDateTime_TimeZone *self, timezone_richcompare(PyDateTime_TimeZone *self,
PyDateTime_TimeZone *other, int op) PyDateTime_TimeZone *other, int op)
{ {
if (op != Py_EQ && op != Py_NE) { if (op != Py_EQ && op != Py_NE)
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
return delta_richcompare(self->offset, other->offset, op); return delta_richcompare(self->offset, other->offset, op);
} }
@ -3664,10 +3651,8 @@ time_richcompare(PyObject *self, PyObject *other, int op)
PyObject *offset1, *offset2; PyObject *offset1, *offset2;
int diff; int diff;
if (! PyTime_Check(other)) { if (! PyTime_Check(other))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
if (GET_TIME_TZINFO(self) == GET_TIME_TZINFO(other)) { if (GET_TIME_TZINFO(self) == GET_TIME_TZINFO(other)) {
diff = memcmp(((PyDateTime_Time *)self)->data, diff = memcmp(((PyDateTime_Time *)self)->data,
@ -4356,8 +4341,7 @@ datetime_add(PyObject *left, PyObject *right)
(PyDateTime_Delta *) left, (PyDateTime_Delta *) left,
1); 1);
} }
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
static PyObject * static PyObject *
@ -4559,8 +4543,7 @@ datetime_richcompare(PyObject *self, PyObject *other, int op)
Py_RETURN_TRUE; Py_RETURN_TRUE;
return cmperror(self, other); return cmperror(self, other);
} }
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
if (GET_DT_TZINFO(self) == GET_DT_TZINFO(other)) { if (GET_DT_TZINFO(self) == GET_DT_TZINFO(other)) {

View 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) static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other, int opid)
{ {
if (opid != Py_EQ && opid != Py_NE) { if (opid != Py_EQ && opid != Py_NE)
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
if (PyType_IsSubtype(Py_TYPE(_other), &pysqlite_RowType)) { if (PyType_IsSubtype(Py_TYPE(_other), &pysqlite_RowType)) {
pysqlite_Row *other = (pysqlite_Row *)_other; pysqlite_Row *other = (pysqlite_Row *)_other;
PyObject *res = PyObject_RichCompare(self->description, other->description, opid); 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); return PyObject_RichCompare(self->data, other->data, opid);
} }
} }
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
PyMappingMethods pysqlite_row_as_mapping = { PyMappingMethods pysqlite_row_as_mapping = {

View File

@ -514,10 +514,8 @@ array_richcompare(PyObject *v, PyObject *w, int op)
Py_ssize_t i, k; Py_ssize_t i, k;
PyObject *res; PyObject *res;
if (!array_Check(v) || !array_Check(w)) { if (!array_Check(v) || !array_Check(w))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
va = (arrayobject *)v; va = (arrayobject *)v;
wa = (arrayobject *)w; wa = (arrayobject *)w;

View File

@ -4925,10 +4925,9 @@ cpu_set_richcompare(Py_cpu_set *set, Py_cpu_set *other, int op)
{ {
int eq; int eq;
if ((op != Py_EQ && op != Py_NE) || Py_TYPE(other) != &cpu_set_type) { if ((op != Py_EQ && op != Py_NE) || Py_TYPE(other) != &cpu_set_type)
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
eq = set->ncpus == other->ncpus && CPU_EQUAL_S(set->size, set->set, other->set); eq = set->ncpus == other->ncpus && CPU_EQUAL_S(set->size, set->set, other->set);
if ((op == Py_EQ) ? eq : !eq) if ((op == Py_EQ) ? eq : !eq)
Py_RETURN_TRUE; 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) { \ if (Py_TYPE(right) != &cpu_set_type || left->ncpus != right->ncpus) { \
Py_DECREF(res); \ Py_DECREF(res); \
Py_INCREF(Py_NotImplemented); \ Py_RETURN_NOTIMPLEMENTED; \
return Py_NotImplemented; \
} \ } \
assert(left->size == right->size && right->size == res->size); \ assert(left->size == right->size && right->size == res->size); \
op(res->size, res->set, left->set, right->set); \ op(res->size, res->set, left->set, right->set); \

View File

@ -187,8 +187,7 @@ static PyType_Spec Str_Type_spec = {
static PyObject * static PyObject *
null_richcompare(PyObject *self, PyObject *other, int op) null_richcompare(PyObject *self, PyObject *other, int op)
{ {
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
static PyType_Slot Null_Type_slots[] = { static PyType_Slot Null_Type_slots[] = {

View File

@ -793,8 +793,7 @@ binary_op1(PyObject *v, PyObject *w, const int op_slot)
return x; return x;
Py_DECREF(x); /* can't do it */ Py_DECREF(x); /* can't do it */
} }
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
static PyObject * static PyObject *

View File

@ -964,23 +964,20 @@ bytearray_richcompare(PyObject *self, PyObject *other, int op)
return NULL; return NULL;
} }
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
self_size = _getbuffer(self, &self_bytes); self_size = _getbuffer(self, &self_bytes);
if (self_size < 0) { if (self_size < 0) {
PyErr_Clear(); PyErr_Clear();
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
other_size = _getbuffer(other, &other_bytes); other_size = _getbuffer(other, &other_bytes);
if (other_size < 0) { if (other_size < 0) {
PyErr_Clear(); PyErr_Clear();
PyBuffer_Release(&self_bytes); PyBuffer_Release(&self_bytes);
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
if (self_size != other_size && (op == Py_EQ || op == Py_NE)) { if (self_size != other_size && (op == Py_EQ || op == Py_NE)) {

View File

@ -190,8 +190,7 @@ method_richcompare(PyObject *self, PyObject *other, int op)
!PyMethod_Check(self) || !PyMethod_Check(self) ||
!PyMethod_Check(other)) !PyMethod_Check(other))
{ {
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
a = (PyMethodObject *)self; a = (PyMethodObject *)self;
b = (PyMethodObject *)other; b = (PyMethodObject *)other;
@ -516,8 +515,7 @@ instancemethod_richcompare(PyObject *self, PyObject *other, int op)
!PyInstanceMethod_Check(self) || !PyInstanceMethod_Check(self) ||
!PyInstanceMethod_Check(other)) !PyInstanceMethod_Check(other))
{ {
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
a = (PyInstanceMethodObject *)self; a = (PyInstanceMethodObject *)self;
b = (PyInstanceMethodObject *)other; b = (PyInstanceMethodObject *)other;

View File

@ -402,8 +402,7 @@ code_richcompare(PyObject *self, PyObject *other, int op)
if ((op != Py_EQ && op != Py_NE) || if ((op != Py_EQ && op != Py_NE) ||
!PyCode_Check(self) || !PyCode_Check(self) ||
!PyCode_Check(other)) { !PyCode_Check(other)) {
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
co = (PyCodeObject *)self; co = (PyCodeObject *)self;

View File

@ -650,8 +650,7 @@ complex_richcompare(PyObject *v, PyObject *w, int op)
return res; return res;
Unimplemented: Unimplemented:
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
static PyObject * static PyObject *

View File

@ -2608,10 +2608,8 @@ dictview_richcompare(PyObject *self, PyObject *other, int op)
assert(PyDictViewSet_Check(self)); assert(PyDictViewSet_Check(self));
assert(other != NULL); assert(other != NULL);
if (!PyAnySet_Check(other) && !PyDictViewSet_Check(other)) { if (!PyAnySet_Check(other) && !PyDictViewSet_Check(other))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
len_self = PyObject_Size(self); len_self = PyObject_Size(self);
if (len_self < 0) if (len_self < 0)

View File

@ -517,8 +517,7 @@ float_richcompare(PyObject *v, PyObject *w, int op)
return PyBool_FromLong(r); return PyBool_FromLong(r);
Unimplemented: Unimplemented:
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
static Py_hash_t static Py_hash_t

View File

@ -2225,10 +2225,8 @@ list_richcompare(PyObject *v, PyObject *w, int op)
PyListObject *vl, *wl; PyListObject *vl, *wl;
Py_ssize_t i; Py_ssize_t i;
if (!PyList_Check(v) || !PyList_Check(w)) { if (!PyList_Check(v) || !PyList_Check(w))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
vl = (PyListObject *)v; vl = (PyListObject *)v;
wl = (PyListObject *)w; wl = (PyListObject *)w;

View File

@ -1382,10 +1382,8 @@ PyLong_AsLongLongAndOverflow(PyObject *vv, int *overflow)
#define CHECK_BINOP(v,w) \ #define CHECK_BINOP(v,w) \
do { \ do { \
if (!PyLong_Check(v) || !PyLong_Check(w)) { \ if (!PyLong_Check(v) || !PyLong_Check(w)) \
Py_INCREF(Py_NotImplemented); \ Py_RETURN_NOTIMPLEMENTED; \
return Py_NotImplemented; \
} \
} while(0) } while(0)
/* bits_in_digit(d) returns the unique integer k such that 2**(k-1) <= d < /* 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 { else {
Py_DECREF(a); Py_DECREF(a);
Py_DECREF(b); Py_DECREF(b);
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
if (Py_SIZE(b) < 0) { /* if exponent is negative */ if (Py_SIZE(b) < 0) { /* if exponent is negative */

View File

@ -773,8 +773,7 @@ _end:
_notimpl: _notimpl:
PyBuffer_Release(&vv); PyBuffer_Release(&vv);
PyBuffer_Release(&ww); PyBuffer_Release(&ww);
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }

View File

@ -208,8 +208,7 @@ meth_richcompare(PyObject *self, PyObject *other, int op)
!PyCFunction_Check(self) || !PyCFunction_Check(self) ||
!PyCFunction_Check(other)) !PyCFunction_Check(other))
{ {
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
a = (PyCFunctionObject *)self; a = (PyCFunctionObject *)self;
b = (PyCFunctionObject *)other; b = (PyCFunctionObject *)other;

View File

@ -1392,8 +1392,7 @@ notimplemented_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyErr_SetString(PyExc_TypeError, "NotImplementedType takes no arguments"); PyErr_SetString(PyExc_TypeError, "NotImplementedType takes no arguments");
return NULL; return NULL;
} }
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
static PyTypeObject PyNotImplemented_Type = { static PyTypeObject PyNotImplemented_Type = {

View File

@ -1212,10 +1212,8 @@ set_or(PySetObject *so, PyObject *other)
{ {
PySetObject *result; PySetObject *result;
if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) { if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
result = (PySetObject *)set_copy(so); result = (PySetObject *)set_copy(so);
if (result == NULL) if (result == NULL)
@ -1232,10 +1230,9 @@ set_or(PySetObject *so, PyObject *other)
static PyObject * static PyObject *
set_ior(PySetObject *so, PyObject *other) set_ior(PySetObject *so, PyObject *other)
{ {
if (!PyAnySet_Check(other)) { if (!PyAnySet_Check(other))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
if (set_update_internal(so, other) == -1) if (set_update_internal(so, other) == -1)
return NULL; return NULL;
Py_INCREF(so); Py_INCREF(so);
@ -1385,10 +1382,8 @@ PyDoc_STRVAR(intersection_update_doc,
static PyObject * static PyObject *
set_and(PySetObject *so, PyObject *other) set_and(PySetObject *so, PyObject *other)
{ {
if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) { if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
return set_intersection(so, other); return set_intersection(so, other);
} }
@ -1397,10 +1392,8 @@ set_iand(PySetObject *so, PyObject *other)
{ {
PyObject *result; PyObject *result;
if (!PyAnySet_Check(other)) { if (!PyAnySet_Check(other))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
result = set_intersection_update(so, other); result = set_intersection_update(so, other);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
@ -1627,20 +1620,16 @@ PyDoc_STRVAR(difference_doc,
static PyObject * static PyObject *
set_sub(PySetObject *so, PyObject *other) set_sub(PySetObject *so, PyObject *other)
{ {
if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) { if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
return set_difference(so, other); return set_difference(so, other);
} }
static PyObject * static PyObject *
set_isub(PySetObject *so, PyObject *other) set_isub(PySetObject *so, PyObject *other)
{ {
if (!PyAnySet_Check(other)) { if (!PyAnySet_Check(other))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
if (set_difference_update_internal(so, other) == -1) if (set_difference_update_internal(so, other) == -1)
return NULL; return NULL;
Py_INCREF(so); Py_INCREF(so);
@ -1738,10 +1727,8 @@ PyDoc_STRVAR(symmetric_difference_doc,
static PyObject * static PyObject *
set_xor(PySetObject *so, PyObject *other) set_xor(PySetObject *so, PyObject *other)
{ {
if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) { if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
return set_symmetric_difference(so, other); return set_symmetric_difference(so, other);
} }
@ -1750,10 +1737,8 @@ set_ixor(PySetObject *so, PyObject *other)
{ {
PyObject *result; PyObject *result;
if (!PyAnySet_Check(other)) { if (!PyAnySet_Check(other))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
result = set_symmetric_difference_update(so, other); result = set_symmetric_difference_update(so, other);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
@ -1815,10 +1800,9 @@ set_richcompare(PySetObject *v, PyObject *w, int op)
{ {
PyObject *r1, *r2; PyObject *r1, *r2;
if(!PyAnySet_Check(w)) { if(!PyAnySet_Check(w))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
switch (op) { switch (op) {
case Py_EQ: case Py_EQ:
if (PySet_GET_SIZE(v) != PySet_GET_SIZE(w)) if (PySet_GET_SIZE(v) != PySet_GET_SIZE(w))
@ -1848,8 +1832,7 @@ set_richcompare(PySetObject *v, PyObject *w, int op)
Py_RETURN_FALSE; Py_RETURN_FALSE;
return set_issuperset(v, w); return set_issuperset(v, w);
} }
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
static PyObject * static PyObject *

View File

@ -326,10 +326,8 @@ slice_richcompare(PyObject *v, PyObject *w, int op)
PyObject *t2; PyObject *t2;
PyObject *res; PyObject *res;
if (!PySlice_Check(v) || !PySlice_Check(w)) { if (!PySlice_Check(v) || !PySlice_Check(w))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
if (v == w) { if (v == w) {
/* XXX Do we really need this shortcut? /* XXX Do we really need this shortcut?

View File

@ -546,10 +546,8 @@ tuplerichcompare(PyObject *v, PyObject *w, int op)
Py_ssize_t i; Py_ssize_t i;
Py_ssize_t vlen, wlen; Py_ssize_t vlen, wlen;
if (!PyTuple_Check(v) || !PyTuple_Check(w)) { if (!PyTuple_Check(v) || !PyTuple_Check(w))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
vt = (PyTupleObject *)v; vt = (PyTupleObject *)v;
wt = (PyTupleObject *)w; wt = (PyTupleObject *)w;

View File

@ -1212,10 +1212,8 @@ call_maybe(PyObject *o, char *name, PyObject **nameobj, char *format, ...)
func = lookup_maybe(o, name, nameobj); func = lookup_maybe(o, name, nameobj);
if (func == NULL) { if (func == NULL) {
va_end(va); va_end(va);
if (!PyErr_Occurred()) { if (!PyErr_Occurred())
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
return NULL; return NULL;
} }
@ -3449,8 +3447,7 @@ object_reduce_ex(PyObject *self, PyObject *args)
static PyObject * static PyObject *
object_subclasshook(PyObject *cls, PyObject *args) object_subclasshook(PyObject *cls, PyObject *args)
{ {
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
PyDoc_STRVAR(object_subclasshook_doc, PyDoc_STRVAR(object_subclasshook_doc,
@ -4818,8 +4815,7 @@ FUNCNAME(PyObject *self, PyObject *other) \
return call_maybe( \ return call_maybe( \
other, ROPSTR, &rcache_str, "(O)", self); \ other, ROPSTR, &rcache_str, "(O)", self); \
} \ } \
Py_INCREF(Py_NotImplemented); \ Py_RETURN_NOTIMPLEMENTED; \
return Py_NotImplemented; \
} }
#define SLOT1BIN(FUNCNAME, SLOTNAME, OPSTR, ROPSTR) \ #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, return call_method(self, "__pow__", &pow_str,
"(OO)", other, modulus); "(OO)", other, modulus);
} }
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
SLOT0(slot_nb_negative, "__neg__") 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]); func = lookup_method(self, name_op[op], &op_str[op]);
if (func == NULL) { if (func == NULL) {
PyErr_Clear(); PyErr_Clear();
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
args = PyTuple_Pack(1, other); args = PyTuple_Pack(1, other);
if (args == NULL) if (args == NULL)

View File

@ -7417,8 +7417,7 @@ PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)
return v; return v;
} }
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
int int
@ -9291,10 +9290,8 @@ static PyMethodDef unicode_methods[] = {
static PyObject * static PyObject *
unicode_mod(PyObject *v, PyObject *w) unicode_mod(PyObject *v, PyObject *w)
{ {
if (!PyUnicode_Check(v)) { if (!PyUnicode_Check(v))
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
}
return PyUnicode_Format(v, w); return PyUnicode_Format(v, w);
} }

View File

@ -193,8 +193,7 @@ weakref_richcompare(PyWeakReference* self, PyWeakReference* other, int op)
if ((op != Py_EQ && op != Py_NE) || if ((op != Py_EQ && op != Py_NE) ||
!PyWeakref_Check(self) || !PyWeakref_Check(self) ||
!PyWeakref_Check(other)) { !PyWeakref_Check(other)) {
Py_INCREF(Py_NotImplemented); Py_RETURN_NOTIMPLEMENTED;
return Py_NotImplemented;
} }
if (PyWeakref_GET_OBJECT(self) == Py_None if (PyWeakref_GET_OBJECT(self) == Py_None
|| PyWeakref_GET_OBJECT(other) == Py_None) { || PyWeakref_GET_OBJECT(other) == Py_None) {