]> granicus.if.org Git - python/commitdiff
Given the persistent id code a shot at a class before calling save_global().
authorJeremy Hylton <jeremy@alum.mit.edu>
Tue, 16 Jul 2002 19:47:43 +0000 (19:47 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Tue, 16 Jul 2002 19:47:43 +0000 (19:47 +0000)
Some persistent picklers (well, probably, the *only* persistent
pickler) would like to pickle some classes in a special way.

Lib/pickle.py
Modules/cPickle.c

index e553920b12cd8044ad6e5b59390e896c75be1368..a507595203e7ec55525b5ac0db87c41ca4597fff 100644 (file)
@@ -213,6 +213,11 @@ class Pickler:
         try:
             f = self.dispatch[t]
         except KeyError:
+            pid = self.inst_persistent_id(object)
+            if pid is not None:
+                self.save_pers(pid)
+                return
+
             try:
                 issc = issubclass(t, TypeType)
             except TypeError: # t is not a class
@@ -221,11 +226,6 @@ class Pickler:
                 self.save_global(object)
                 return
 
-            pid = self.inst_persistent_id(object)
-            if pid is not None:
-                self.save_pers(pid)
-                return
-
             try:
                 reduce = dispatch_table[t]
             except KeyError:
index 91a63bf6eb715eef59f0261634aa93e799c1522c..ce326830fb0c2fb4dab90efa541475ae45f6c375 100644 (file)
@@ -2015,11 +2015,6 @@ save(Picklerobject *self, PyObject *args, int  pers_save)
                }
        }
 
-       if (PyType_IsSubtype(type, &PyType_Type)) {
-               res = save_global(self, args, NULL);
-               goto finally;
-       }
-
        if (!pers_save && self->inst_pers_func) {
                if ((tmp = save_pers(self, args, self->inst_pers_func)) != 0) {
                        res = tmp;
@@ -2027,6 +2022,11 @@ save(Picklerobject *self, PyObject *args, int  pers_save)
                }
        }
 
+       if (PyType_IsSubtype(type, &PyType_Type)) {
+               res = save_global(self, args, NULL);
+               goto finally;
+       }
+
        if ((__reduce__ = PyDict_GetItem(dispatch_table, (PyObject *)type))) {
                Py_INCREF(__reduce__);