The macro was introduced in #12724.
if (!PyObject_TypeCheck(v, &deque_type) ||
!PyObject_TypeCheck(w, &deque_type)) {
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
/* Shortcuts */
return diff_to_bool(diff, op);
}
else {
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
}
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)
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)
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))
(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 */
1);
}
}
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
_PyDateTime_DATE_DATASIZE);
return diff_to_bool(diff, op);
}
- else {
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
- }
+ else
+ Py_RETURN_NOTIMPLEMENTED;
}
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);
}
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,
(PyDateTime_Delta *) left,
1);
}
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
static PyObject *
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)) {
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);
return PyObject_RichCompare(self->data, other->data, opid);
}
}
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
PyMappingMethods pysqlite_row_as_mapping = {
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;
{
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;
} \
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); \
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[] = {
return x;
Py_DECREF(x); /* can't do it */
}
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
static PyObject *
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)) {
!PyMethod_Check(self) ||
!PyMethod_Check(other))
{
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
a = (PyMethodObject *)self;
b = (PyMethodObject *)other;
!PyInstanceMethod_Check(self) ||
!PyInstanceMethod_Check(other))
{
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
a = (PyInstanceMethodObject *)self;
b = (PyInstanceMethodObject *)other;
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;
return res;
Unimplemented:
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
static PyObject *
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)
return PyBool_FromLong(r);
Unimplemented:
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
static Py_hash_t
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;
#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 <
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 */
_notimpl:
PyBuffer_Release(&vv);
PyBuffer_Release(&ww);
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
!PyCFunction_Check(self) ||
!PyCFunction_Check(other))
{
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
a = (PyCFunctionObject *)self;
b = (PyCFunctionObject *)other;
PyErr_SetString(PyExc_TypeError, "NotImplementedType takes no arguments");
return NULL;
}
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
static PyTypeObject PyNotImplemented_Type = {
{
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)
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);
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);
}
{
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;
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);
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);
}
{
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;
{
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))
Py_RETURN_FALSE;
return set_issuperset(v, w);
}
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
static PyObject *
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?
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;
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;
}
static PyObject *
object_subclasshook(PyObject *cls, PyObject *args)
{
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
PyDoc_STRVAR(object_subclasshook_doc,
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) \
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__")
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)
return v;
}
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
int
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);
}
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) {