From 39c6116483bd7932cee220943e329c5994f62cc7 Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Tue, 16 Jul 2002 19:47:43 +0000 Subject: Given the persistent id code a shot at a class before calling save_global(). Some persistent picklers (well, probably, the *only* persistent pickler) would like to pickle some classes in a special way. --- Lib/pickle.py | 10 +++++----- Modules/cPickle.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Lib/pickle.py b/Lib/pickle.py index e553920..a507595 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -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: diff --git a/Modules/cPickle.c b/Modules/cPickle.c index 91a63bf..ce32683 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -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__); -- cgit v0.12