Issue #20440: Cleaning up the code by using Py_SETREF.
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;
 }