Replace Py_NotImplemented returns with the macro form Py_RETURN_NOTIMPLEMENTED.
The macro was introduced in #12724.
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 747be45..718dfe2 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -1812,8 +1812,7 @@
return diff_to_bool(diff, op);
}
else {
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
}
@@ -1911,10 +1910,8 @@
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 @@
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 @@
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 @@
(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 @@
1);
}
}
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
@@ -2715,10 +2706,8 @@
_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 @@
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 @@
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 @@
(PyDateTime_Delta *) left,
1);
}
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ Py_RETURN_NOTIMPLEMENTED;
}
static PyObject *
@@ -4559,8 +4543,7 @@
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)) {