Skip to content

Commit d1302c0

Browse files
Issue python#28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE wherever
possible but Coccinelle couldn't find opportunity.
1 parent 228b12e commit d1302c0

5 files changed

Lines changed: 10 additions & 19 deletions

File tree

Include/py_curses.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,16 @@ static PyObject *PyCurses_ ## X (PyObject *self) \
154154
{ \
155155
PyCursesInitialised \
156156
if (X () == FALSE) { \
157-
Py_INCREF(Py_False); \
158-
return Py_False; \
157+
Py_RETURN_FALSE; \
159158
} \
160-
Py_INCREF(Py_True); \
161-
return Py_True; }
159+
Py_RETURN_TRUE; }
162160

163161
#define NoArgNoReturnVoidFunction(X) \
164162
static PyObject *PyCurses_ ## X (PyObject *self) \
165163
{ \
166164
PyCursesInitialised \
167165
X(); \
168-
Py_INCREF(Py_None); \
169-
return Py_None; }
166+
Py_RETURN_NONE; }
170167

171168
#ifdef __cplusplus
172169
}

Modules/_ctypes/cfield.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ get_ulonglong(PyObject *v, unsigned long long *p)
498498
#ifdef _CTYPES_DEBUG_KEEP
499499
#define _RET(x) Py_INCREF(x); return x
500500
#else
501-
#define _RET(X) Py_INCREF(Py_None); return Py_None
501+
#define _RET(X) Py_RETURN_NONE
502502
#endif
503503

504504
/*****************************************************************

Modules/_json.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,17 +1108,15 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
11081108
case 'n':
11091109
/* null */
11101110
if ((idx + 3 < length) && PyUnicode_READ(kind, str, idx + 1) == 'u' && PyUnicode_READ(kind, str, idx + 2) == 'l' && PyUnicode_READ(kind, str, idx + 3) == 'l') {
1111-
Py_INCREF(Py_None);
11121111
*next_idx_ptr = idx + 4;
1113-
return Py_None;
1112+
Py_RETURN_NONE;
11141113
}
11151114
break;
11161115
case 't':
11171116
/* true */
11181117
if ((idx + 3 < length) && PyUnicode_READ(kind, str, idx + 1) == 'r' && PyUnicode_READ(kind, str, idx + 2) == 'u' && PyUnicode_READ(kind, str, idx + 3) == 'e') {
1119-
Py_INCREF(Py_True);
11201118
*next_idx_ptr = idx + 4;
1121-
return Py_True;
1119+
Py_RETURN_TRUE;
11221120
}
11231121
break;
11241122
case 'f':
@@ -1127,9 +1125,8 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
11271125
PyUnicode_READ(kind, str, idx + 2) == 'l' &&
11281126
PyUnicode_READ(kind, str, idx + 3) == 's' &&
11291127
PyUnicode_READ(kind, str, idx + 4) == 'e') {
1130-
Py_INCREF(Py_False);
11311128
*next_idx_ptr = idx + 5;
1132-
return Py_False;
1129+
Py_RETURN_FALSE;
11331130
}
11341131
break;
11351132
case 'N':

Modules/_testcapimodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ test_sizeof_c_types(PyObject *self)
117117
CHECK_SIZEOF(intptr_t, sizeof(void *));
118118
CHECK_SIGNNESS(intptr_t, 1);
119119

120-
Py_INCREF(Py_None);
121-
return Py_None;
120+
Py_RETURN_NONE;
122121

123122
#undef IS_SIGNED
124123
#undef CHECK_SIGNESS

Objects/stringlib/unicode_format.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ SubString_init(SubString *str, PyObject *s, Py_ssize_t start, Py_ssize_t end)
6060
Py_LOCAL_INLINE(PyObject *)
6161
SubString_new_object(SubString *str)
6262
{
63-
if (str->str == NULL) {
64-
Py_INCREF(Py_None);
65-
return Py_None;
66-
}
63+
if (str->str == NULL)
64+
Py_RETURN_NONE;
6765
return PyUnicode_Substring(str->str, str->start, str->end);
6866
}
6967

0 commit comments

Comments
 (0)