mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE wherever
possible. Patch is writen with Coccinelle.
This commit is contained in:
parent
60e6e962ba
commit
228b12edcc
57 changed files with 225 additions and 445 deletions
|
@ -419,8 +419,7 @@ static PyObject *
|
|||
member_get_doc(PyMemberDescrObject *descr, void *closure)
|
||||
{
|
||||
if (descr->d_member->doc == NULL) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
return PyUnicode_FromString(descr->d_member->doc);
|
||||
}
|
||||
|
@ -435,8 +434,7 @@ static PyObject *
|
|||
getset_get_doc(PyGetSetDescrObject *descr, void *closure)
|
||||
{
|
||||
if (descr->d_getset->doc == NULL) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
return PyUnicode_FromString(descr->d_getset->doc);
|
||||
}
|
||||
|
|
|
@ -184,8 +184,7 @@ static PyObject *
|
|||
BaseException_get_args(PyBaseExceptionObject *self)
|
||||
{
|
||||
if (self->args == NULL) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
Py_INCREF(self->args);
|
||||
return self->args;
|
||||
|
@ -210,8 +209,7 @@ static PyObject *
|
|||
BaseException_get_tb(PyBaseExceptionObject *self)
|
||||
{
|
||||
if (self->traceback == NULL) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
Py_INCREF(self->traceback);
|
||||
return self->traceback;
|
||||
|
|
|
@ -456,8 +456,7 @@ static PyMethodDef stdprinter_methods[] = {
|
|||
static PyObject *
|
||||
get_closed(PyStdPrinter_Object *self, void *closure)
|
||||
{
|
||||
Py_INCREF(Py_False);
|
||||
return Py_False;
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
|
@ -322,8 +322,7 @@ static PyObject *
|
|||
func_get_defaults(PyFunctionObject *op)
|
||||
{
|
||||
if (op->func_defaults == NULL) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
Py_INCREF(op->func_defaults);
|
||||
return op->func_defaults;
|
||||
|
@ -350,8 +349,7 @@ static PyObject *
|
|||
func_get_kwdefaults(PyFunctionObject *op)
|
||||
{
|
||||
if (op->func_kwdefaults == NULL) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
Py_INCREF(op->func_kwdefaults);
|
||||
return op->func_kwdefaults;
|
||||
|
|
|
@ -402,8 +402,7 @@ gen_close(PyGenObject *gen, PyObject *args)
|
|||
if (PyErr_ExceptionMatches(PyExc_StopIteration)
|
||||
|| PyErr_ExceptionMatches(PyExc_GeneratorExit)) {
|
||||
PyErr_Clear(); /* ignore these errors */
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -2284,12 +2284,10 @@ list_richcompare(PyObject *v, PyObject *w, int op)
|
|||
|
||||
/* We have an item that differs -- shortcuts for EQ/NE */
|
||||
if (op == Py_EQ) {
|
||||
Py_INCREF(Py_False);
|
||||
return Py_False;
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
if (op == Py_NE) {
|
||||
Py_INCREF(Py_True);
|
||||
return Py_True;
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
/* Compare the final item again using the proper operator */
|
||||
|
|
|
@ -631,12 +631,10 @@ tuplerichcompare(PyObject *v, PyObject *w, int op)
|
|||
|
||||
/* We have an item that differs -- shortcuts for EQ/NE */
|
||||
if (op == Py_EQ) {
|
||||
Py_INCREF(Py_False);
|
||||
return Py_False;
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
if (op == Py_NE) {
|
||||
Py_INCREF(Py_True);
|
||||
return Py_True;
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
/* Compare the final item again using the proper operator */
|
||||
|
|
|
@ -140,8 +140,7 @@ _PyType_GetDocFromInternalDoc(const char *name, const char *internal_doc)
|
|||
const char *doc = _PyType_DocWithoutSignature(name, internal_doc);
|
||||
|
||||
if (!doc || *doc == '\0') {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
return PyUnicode_FromString(doc);
|
||||
|
@ -158,8 +157,7 @@ _PyType_GetTextSignatureFromInternalDoc(const char *name, const char *internal_d
|
|||
else
|
||||
end = NULL;
|
||||
if (!end) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* back "end" up until it points just past the final ')' */
|
||||
|
@ -761,8 +759,7 @@ static PyObject *
|
|||
type_dict(PyTypeObject *type, void *context)
|
||||
{
|
||||
if (type->tp_dict == NULL) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
return PyDictProxy_New(type->tp_dict);
|
||||
}
|
||||
|
@ -5330,8 +5327,7 @@ wrap_sq_setitem(PyObject *self, PyObject *args, void *wrapped)
|
|||
res = (*func)(self, i, value);
|
||||
if (res == -1 && PyErr_Occurred())
|
||||
return NULL;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -5351,8 +5347,7 @@ wrap_sq_delitem(PyObject *self, PyObject *args, void *wrapped)
|
|||
res = (*func)(self, i, NULL);
|
||||
if (res == -1 && PyErr_Occurred())
|
||||
return NULL;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* XXX objobjproc is a misnomer; should be objargpred */
|
||||
|
@ -5385,8 +5380,7 @@ wrap_objobjargproc(PyObject *self, PyObject *args, void *wrapped)
|
|||
res = (*func)(self, key, value);
|
||||
if (res == -1 && PyErr_Occurred())
|
||||
return NULL;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -5402,8 +5396,7 @@ wrap_delitem(PyObject *self, PyObject *args, void *wrapped)
|
|||
res = (*func)(self, key, NULL);
|
||||
if (res == -1 && PyErr_Occurred())
|
||||
return NULL;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* Helper to check for object.__setattr__ or __delattr__ applied to a type.
|
||||
|
@ -5440,8 +5433,7 @@ wrap_setattr(PyObject *self, PyObject *args, void *wrapped)
|
|||
res = (*func)(self, name, value);
|
||||
if (res < 0)
|
||||
return NULL;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -5459,8 +5451,7 @@ wrap_delattr(PyObject *self, PyObject *args, void *wrapped)
|
|||
res = (*func)(self, name, NULL);
|
||||
if (res < 0)
|
||||
return NULL;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -5571,8 +5562,7 @@ wrap_descr_set(PyObject *self, PyObject *args, void *wrapped)
|
|||
ret = (*func)(self, obj, value);
|
||||
if (ret < 0)
|
||||
return NULL;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -5588,8 +5578,7 @@ wrap_descr_delete(PyObject *self, PyObject *args, void *wrapped)
|
|||
ret = (*func)(self, obj, NULL);
|
||||
if (ret < 0)
|
||||
return NULL;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -5599,8 +5588,7 @@ wrap_init(PyObject *self, PyObject *args, void *wrapped, PyObject *kwds)
|
|||
|
||||
if (func(self, args, kwds) < 0)
|
||||
return NULL;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
|
@ -8254,9 +8254,7 @@ charmapencode_lookup(Py_UCS4 c, PyObject *mapping)
|
|||
if (PyErr_ExceptionMatches(PyExc_LookupError)) {
|
||||
/* No mapping found means: mapping is undefined. */
|
||||
PyErr_Clear();
|
||||
x = Py_None;
|
||||
Py_INCREF(x);
|
||||
return x;
|
||||
Py_RETURN_NONE;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue