Issue #20440: Cleaning up the code by using Py_SETREF.
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 3e5e195..4c8f3f6 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -1057,10 +1057,8 @@
     }
     /* Offset is normalized, so it is negative if days < 0 */
     if (GET_TD_DAYS(offset) < 0) {
-        PyObject *temp = offset;
         sign = '-';
-        offset = delta_negative((PyDateTime_Delta *)offset);
-        Py_DECREF(temp);
+        Py_SETREF(offset, delta_negative((PyDateTime_Delta *)offset));
         if (offset == NULL)
             return -1;
     }
@@ -3047,10 +3045,8 @@
     if (dst == Py_None)
         goto Inconsistent;
     if (delta_bool((PyDateTime_Delta *)dst) != 0) {
-        PyObject *temp = result;
-        result = add_datetime_timedelta((PyDateTime_DateTime *)result,
-                                        (PyDateTime_Delta *)dst, 1);
-        Py_DECREF(temp);
+        Py_SETREF(result, add_datetime_timedelta((PyDateTime_DateTime *)result,
+                                                 (PyDateTime_Delta *)dst, 1));
         if (result == NULL)
             goto Fail;
     }
@@ -4157,10 +4153,7 @@
                                   tz);
     if (self != NULL && tz != Py_None) {
         /* Convert UTC to tzinfo's zone. */
-        PyObject *temp = self;
-
-        self = _PyObject_CallMethodId(tz, &PyId_fromutc, "O", self);
-        Py_DECREF(temp);
+        self = _PyObject_CallMethodId(tz, &PyId_fromutc, "N", self);
     }
     return self;
 }
@@ -4195,10 +4188,7 @@
                                    tzinfo);
     if (self != NULL && tzinfo != Py_None) {
         /* Convert UTC to tzinfo's zone. */
-        PyObject *temp = self;
-
-        self = _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "O", self);
-        Py_DECREF(temp);
+        self = _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "N", self);
     }
     return self;
 }
@@ -4421,9 +4411,7 @@
                 return NULL;
 
             if (offdiff != NULL) {
-                PyObject *temp = result;
-                result = delta_subtract(result, offdiff);
-                Py_DECREF(temp);
+                Py_SETREF(result, delta_subtract(result, offdiff));
                 Py_DECREF(offdiff);
             }
         }
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 580c53a..0effc3f 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -396,10 +396,8 @@
     Py_XDECREF(attrib);
 
     /* Replace the objects already pointed to by tag, text and tail. */
-    tmp = self_elem->tag;
     Py_INCREF(tag);
-    self_elem->tag = tag;
-    Py_DECREF(tmp);
+    Py_SETREF(self_elem->tag, tag);
 
     tmp = self_elem->text;
     Py_INCREF(Py_None);
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
index 66e534f..d3ed758 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -762,7 +762,6 @@
 static int
 profiler_init(ProfilerObject *pObj, PyObject *args, PyObject *kw)
 {
-    PyObject *o;
     PyObject *timer = NULL;
     double timeunit = 0.0;
     int subcalls = 1;
@@ -777,11 +776,9 @@
 
     if (setSubcalls(pObj, subcalls) < 0 || setBuiltins(pObj, builtins) < 0)
         return -1;
-    o = pObj->externalTimer;
-    pObj->externalTimer = timer;
-    Py_XINCREF(timer);
-    Py_XDECREF(o);
     pObj->externalTimerUnit = timeunit;
+    Py_XINCREF(timer);
+    Py_SETREF(pObj->externalTimer, timer);
     return 0;
 }
 
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index b42f4f6..bb3330a 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -4494,8 +4494,6 @@
 static int
 Pickler_set_persid(PicklerObject *self, PyObject *value)
 {
-    PyObject *tmp;
-
     if (value == NULL) {
         PyErr_SetString(PyExc_TypeError,
                         "attribute deletion is not supported");
@@ -4507,10 +4505,8 @@
         return -1;
     }
 
-    tmp = self->pers_func;
     Py_INCREF(value);
-    self->pers_func = value;
-    Py_XDECREF(tmp);      /* self->pers_func can be NULL, so be careful. */
+    Py_SETREF(self->pers_func, value);
 
     return 0;
 }
@@ -6946,8 +6942,6 @@
 static int
 Unpickler_set_persload(UnpicklerObject *self, PyObject *value)
 {
-    PyObject *tmp;
-
     if (value == NULL) {
         PyErr_SetString(PyExc_TypeError,
                         "attribute deletion is not supported");
@@ -6960,10 +6954,8 @@
         return -1;
     }
 
-    tmp = self->pers_func;
     Py_INCREF(value);
-    self->pers_func = value;
-    Py_XDECREF(tmp);      /* self->pers_func can be NULL, so be careful. */
+    Py_SETREF(self->pers_func, value);
 
     return 0;
 }
diff --git a/Modules/readline.c b/Modules/readline.c
index 939ff1a..6930415 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -321,10 +321,8 @@
         Py_CLEAR(*hook_var);
     }
     else if (PyCallable_Check(function)) {
-        PyObject *tmp = *hook_var;
         Py_INCREF(function);
-        *hook_var = function;
-        Py_XDECREF(tmp);
+        Py_SETREF(*hook_var, function);
     }
     else {
         PyErr_Format(PyExc_TypeError,