mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Replace Py_NotImplemented returns with the macro form Py_RETURN_NOTIMPLEMENTED.
The macro was introduced in #12724.
This commit is contained in:
parent
7d2f9e1342
commit
dfc80e3d97
24 changed files with 87 additions and 162 deletions
|
|
@ -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 *
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 *
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -773,8 +773,7 @@ _end:
|
|||
_notimpl:
|
||||
PyBuffer_Release(&vv);
|
||||
PyBuffer_Release(&ww);
|
||||
Py_INCREF(Py_NotImplemented);
|
||||
return Py_NotImplemented;
|
||||
Py_RETURN_NOTIMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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 *
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue