Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE wherever
possible.  Patch is writen with Coccinelle.
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index a254a2a..3fb34a3 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -419,8 +419,7 @@
 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 @@
 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);
 }
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 57a786c..35a8b66 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -184,8 +184,7 @@
 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 @@
 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;
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index fcdb5fd..3c3d46d 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -456,8 +456,7 @@
 static PyObject *
 get_closed(PyStdPrinter_Object *self, void *closure)
 {
-    Py_INCREF(Py_False);
-    return Py_False;
+    Py_RETURN_FALSE;
 }
 
 static PyObject *
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index a3af4b3..8ac88b1 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -322,8 +322,7 @@
 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 @@
 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;
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 59f53ce..24a1da6 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -402,8 +402,7 @@
     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;
 }
diff --git a/Objects/listobject.c b/Objects/listobject.c
index b21f637..8994174 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2284,12 +2284,10 @@
 
     /* 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 */
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index c0ff499..5bcadeb 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -631,12 +631,10 @@
 
     /* 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 */
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 0fdff31..bf6d3f1 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -140,8 +140,7 @@
     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 @@
     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 @@
 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 @@
     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 @@
     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 @@
     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 @@
     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 @@
     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 @@
     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 @@
     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 @@
     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 @@
 
     if (func(self, args, kwds) < 0)
         return NULL;
-    Py_INCREF(Py_None);
-    return Py_None;
+    Py_RETURN_NONE;
 }
 
 static PyObject *
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index b711f0c..0b79c5b 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8254,9 +8254,7 @@
         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;
     }