X Tutup
Skip to content

Commit dfc80e3

Browse files
committed
Replace Py_NotImplemented returns with the macro form Py_RETURN_NOTIMPLEMENTED.
The macro was introduced in #12724.
1 parent 7d2f9e1 commit dfc80e3

24 files changed

+87
-162
lines changed

Modules/_collectionsmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,7 @@ deque_richcompare(PyObject *v, PyObject *w, int op)
832832

833833
if (!PyObject_TypeCheck(v, &deque_type) ||
834834
!PyObject_TypeCheck(w, &deque_type)) {
835-
Py_INCREF(Py_NotImplemented);
836-
return Py_NotImplemented;
835+
Py_RETURN_NOTIMPLEMENTED;
837836
}
838837

839838
/* Shortcuts */

Modules/_datetimemodule.c

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,8 +1812,7 @@ delta_richcompare(PyObject *self, PyObject *other, int op)
18121812
return diff_to_bool(diff, op);
18131813
}
18141814
else {
1815-
Py_INCREF(Py_NotImplemented);
1816-
return Py_NotImplemented;
1815+
Py_RETURN_NOTIMPLEMENTED;
18171816
}
18181817
}
18191818

@@ -1911,10 +1910,8 @@ delta_remainder(PyObject *left, PyObject *right)
19111910
PyObject *pyus_remainder;
19121911
PyObject *remainder;
19131912

1914-
if (!PyDelta_Check(left) || !PyDelta_Check(right)) {
1915-
Py_INCREF(Py_NotImplemented);
1916-
return Py_NotImplemented;
1917-
}
1913+
if (!PyDelta_Check(left) || !PyDelta_Check(right))
1914+
Py_RETURN_NOTIMPLEMENTED;
19181915

19191916
pyus_left = delta_to_microseconds((PyDateTime_Delta *)left);
19201917
if (pyus_left == NULL)
@@ -1949,10 +1946,8 @@ delta_divmod(PyObject *left, PyObject *right)
19491946
PyObject *delta;
19501947
PyObject *result;
19511948

1952-
if (!PyDelta_Check(left) || !PyDelta_Check(right)) {
1953-
Py_INCREF(Py_NotImplemented);
1954-
return Py_NotImplemented;
1955-
}
1949+
if (!PyDelta_Check(left) || !PyDelta_Check(right))
1950+
Py_RETURN_NOTIMPLEMENTED;
19561951

19571952
pyus_left = delta_to_microseconds((PyDateTime_Delta *)left);
19581953
if (pyus_left == NULL)
@@ -2546,10 +2541,9 @@ add_date_timedelta(PyDateTime_Date *date, PyDateTime_Delta *delta, int negate)
25462541
static PyObject *
25472542
date_add(PyObject *left, PyObject *right)
25482543
{
2549-
if (PyDateTime_Check(left) || PyDateTime_Check(right)) {
2550-
Py_INCREF(Py_NotImplemented);
2551-
return Py_NotImplemented;
2552-
}
2544+
if (PyDateTime_Check(left) || PyDateTime_Check(right))
2545+
Py_RETURN_NOTIMPLEMENTED;
2546+
25532547
if (PyDate_Check(left)) {
25542548
/* date + ??? */
25552549
if (PyDelta_Check(right))
@@ -2568,17 +2562,15 @@ date_add(PyObject *left, PyObject *right)
25682562
(PyDateTime_Delta *) left,
25692563
0);
25702564
}
2571-
Py_INCREF(Py_NotImplemented);
2572-
return Py_NotImplemented;
2565+
Py_RETURN_NOTIMPLEMENTED;
25732566
}
25742567

25752568
static PyObject *
25762569
date_subtract(PyObject *left, PyObject *right)
25772570
{
2578-
if (PyDateTime_Check(left) || PyDateTime_Check(right)) {
2579-
Py_INCREF(Py_NotImplemented);
2580-
return Py_NotImplemented;
2581-
}
2571+
if (PyDateTime_Check(left) || PyDateTime_Check(right))
2572+
Py_RETURN_NOTIMPLEMENTED;
2573+
25822574
if (PyDate_Check(left)) {
25832575
if (PyDate_Check(right)) {
25842576
/* date - date */
@@ -2597,8 +2589,7 @@ date_subtract(PyObject *left, PyObject *right)
25972589
1);
25982590
}
25992591
}
2600-
Py_INCREF(Py_NotImplemented);
2601-
return Py_NotImplemented;
2592+
Py_RETURN_NOTIMPLEMENTED;
26022593
}
26032594

26042595

@@ -2715,10 +2706,8 @@ date_richcompare(PyObject *self, PyObject *other, int op)
27152706
_PyDateTime_DATE_DATASIZE);
27162707
return diff_to_bool(diff, op);
27172708
}
2718-
else {
2719-
Py_INCREF(Py_NotImplemented);
2720-
return Py_NotImplemented;
2721-
}
2709+
else
2710+
Py_RETURN_NOTIMPLEMENTED;
27222711
}
27232712

27242713
static PyObject *
@@ -3215,10 +3204,8 @@ static PyObject *
32153204
timezone_richcompare(PyDateTime_TimeZone *self,
32163205
PyDateTime_TimeZone *other, int op)
32173206
{
3218-
if (op != Py_EQ && op != Py_NE) {
3219-
Py_INCREF(Py_NotImplemented);
3220-
return Py_NotImplemented;
3221-
}
3207+
if (op != Py_EQ && op != Py_NE)
3208+
Py_RETURN_NOTIMPLEMENTED;
32223209
return delta_richcompare(self->offset, other->offset, op);
32233210
}
32243211

@@ -3664,10 +3651,8 @@ time_richcompare(PyObject *self, PyObject *other, int op)
36643651
PyObject *offset1, *offset2;
36653652
int diff;
36663653

3667-
if (! PyTime_Check(other)) {
3668-
Py_INCREF(Py_NotImplemented);
3669-
return Py_NotImplemented;
3670-
}
3654+
if (! PyTime_Check(other))
3655+
Py_RETURN_NOTIMPLEMENTED;
36713656

36723657
if (GET_TIME_TZINFO(self) == GET_TIME_TZINFO(other)) {
36733658
diff = memcmp(((PyDateTime_Time *)self)->data,
@@ -4356,8 +4341,7 @@ datetime_add(PyObject *left, PyObject *right)
43564341
(PyDateTime_Delta *) left,
43574342
1);
43584343
}
4359-
Py_INCREF(Py_NotImplemented);
4360-
return Py_NotImplemented;
4344+
Py_RETURN_NOTIMPLEMENTED;
43614345
}
43624346

43634347
static PyObject *
@@ -4559,8 +4543,7 @@ datetime_richcompare(PyObject *self, PyObject *other, int op)
45594543
Py_RETURN_TRUE;
45604544
return cmperror(self, other);
45614545
}
4562-
Py_INCREF(Py_NotImplemented);
4563-
return Py_NotImplemented;
4546+
Py_RETURN_NOTIMPLEMENTED;
45644547
}
45654548

45664549
if (GET_DT_TZINFO(self) == GET_DT_TZINFO(other)) {

Modules/_sqlite/row.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ static Py_hash_t pysqlite_row_hash(pysqlite_Row *self)
173173

174174
static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other, int opid)
175175
{
176-
if (opid != Py_EQ && opid != Py_NE) {
177-
Py_INCREF(Py_NotImplemented);
178-
return Py_NotImplemented;
179-
}
176+
if (opid != Py_EQ && opid != Py_NE)
177+
Py_RETURN_NOTIMPLEMENTED;
178+
180179
if (PyType_IsSubtype(Py_TYPE(_other), &pysqlite_RowType)) {
181180
pysqlite_Row *other = (pysqlite_Row *)_other;
182181
PyObject *res = PyObject_RichCompare(self->description, other->description, opid);
@@ -186,8 +185,7 @@ static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other,
186185
return PyObject_RichCompare(self->data, other->data, opid);
187186
}
188187
}
189-
Py_INCREF(Py_NotImplemented);
190-
return Py_NotImplemented;
188+
Py_RETURN_NOTIMPLEMENTED;
191189
}
192190

193191
PyMappingMethods pysqlite_row_as_mapping = {

Modules/arraymodule.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,8 @@ array_richcompare(PyObject *v, PyObject *w, int op)
514514
Py_ssize_t i, k;
515515
PyObject *res;
516516

517-
if (!array_Check(v) || !array_Check(w)) {
518-
Py_INCREF(Py_NotImplemented);
519-
return Py_NotImplemented;
520-
}
517+
if (!array_Check(v) || !array_Check(w))
518+
Py_RETURN_NOTIMPLEMENTED;
521519

522520
va = (arrayobject *)v;
523521
wa = (arrayobject *)w;

Modules/posixmodule.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4925,10 +4925,9 @@ cpu_set_richcompare(Py_cpu_set *set, Py_cpu_set *other, int op)
49254925
{
49264926
int eq;
49274927

4928-
if ((op != Py_EQ && op != Py_NE) || Py_TYPE(other) != &cpu_set_type) {
4929-
Py_INCREF(Py_NotImplemented);
4930-
return Py_NotImplemented;
4931-
}
4928+
if ((op != Py_EQ && op != Py_NE) || Py_TYPE(other) != &cpu_set_type)
4929+
Py_RETURN_NOTIMPLEMENTED;
4930+
49324931
eq = set->ncpus == other->ncpus && CPU_EQUAL_S(set->size, set->set, other->set);
49334932
if ((op == Py_EQ) ? eq : !eq)
49344933
Py_RETURN_TRUE;
@@ -4949,8 +4948,7 @@ cpu_set_richcompare(Py_cpu_set *set, Py_cpu_set *other, int op)
49494948
} \
49504949
if (Py_TYPE(right) != &cpu_set_type || left->ncpus != right->ncpus) { \
49514950
Py_DECREF(res); \
4952-
Py_INCREF(Py_NotImplemented); \
4953-
return Py_NotImplemented; \
4951+
Py_RETURN_NOTIMPLEMENTED; \
49544952
} \
49554953
assert(left->size == right->size && right->size == res->size); \
49564954
op(res->size, res->set, left->set, right->set); \

Modules/xxlimited.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ static PyType_Spec Str_Type_spec = {
187187
static PyObject *
188188
null_richcompare(PyObject *self, PyObject *other, int op)
189189
{
190-
Py_INCREF(Py_NotImplemented);
191-
return Py_NotImplemented;
190+
Py_RETURN_NOTIMPLEMENTED;
192191
}
193192

194193
static PyType_Slot Null_Type_slots[] = {

Objects/abstract.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,7 @@ binary_op1(PyObject *v, PyObject *w, const int op_slot)
793793
return x;
794794
Py_DECREF(x); /* can't do it */
795795
}
796-
Py_INCREF(Py_NotImplemented);
797-
return Py_NotImplemented;
796+
Py_RETURN_NOTIMPLEMENTED;
798797
}
799798

800799
static PyObject *

Objects/bytearrayobject.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -964,23 +964,20 @@ bytearray_richcompare(PyObject *self, PyObject *other, int op)
964964
return NULL;
965965
}
966966

967-
Py_INCREF(Py_NotImplemented);
968-
return Py_NotImplemented;
967+
Py_RETURN_NOTIMPLEMENTED;
969968
}
970969

971970
self_size = _getbuffer(self, &self_bytes);
972971
if (self_size < 0) {
973972
PyErr_Clear();
974-
Py_INCREF(Py_NotImplemented);
975-
return Py_NotImplemented;
973+
Py_RETURN_NOTIMPLEMENTED;
976974
}
977975

978976
other_size = _getbuffer(other, &other_bytes);
979977
if (other_size < 0) {
980978
PyErr_Clear();
981979
PyBuffer_Release(&self_bytes);
982-
Py_INCREF(Py_NotImplemented);
983-
return Py_NotImplemented;
980+
Py_RETURN_NOTIMPLEMENTED;
984981
}
985982

986983
if (self_size != other_size && (op == Py_EQ || op == Py_NE)) {

Objects/classobject.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ method_richcompare(PyObject *self, PyObject *other, int op)
190190
!PyMethod_Check(self) ||
191191
!PyMethod_Check(other))
192192
{
193-
Py_INCREF(Py_NotImplemented);
194-
return Py_NotImplemented;
193+
Py_RETURN_NOTIMPLEMENTED;
195194
}
196195
a = (PyMethodObject *)self;
197196
b = (PyMethodObject *)other;
@@ -516,8 +515,7 @@ instancemethod_richcompare(PyObject *self, PyObject *other, int op)
516515
!PyInstanceMethod_Check(self) ||
517516
!PyInstanceMethod_Check(other))
518517
{
519-
Py_INCREF(Py_NotImplemented);
520-
return Py_NotImplemented;
518+
Py_RETURN_NOTIMPLEMENTED;
521519
}
522520
a = (PyInstanceMethodObject *)self;
523521
b = (PyInstanceMethodObject *)other;

Objects/codeobject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,7 @@ code_richcompare(PyObject *self, PyObject *other, int op)
402402
if ((op != Py_EQ && op != Py_NE) ||
403403
!PyCode_Check(self) ||
404404
!PyCode_Check(other)) {
405-
Py_INCREF(Py_NotImplemented);
406-
return Py_NotImplemented;
405+
Py_RETURN_NOTIMPLEMENTED;
407406
}
408407

409408
co = (PyCodeObject *)self;

0 commit comments

Comments
 (0)
X Tutup