Issue #7689: Allow pickling of dynamically created classes when their
metaclass is registered with copyreg. Patch by Nicolas M. ThiƩry and
Craig Citro.
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index bd577ad..48b5075 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -2697,11 +2697,6 @@
}
}
- if (PyType_IsSubtype(type, &PyType_Type)) {
- res = save_global(self, args, NULL);
- goto finally;
- }
-
/* Get a reduction callable, and call it. This may come from
* copy_reg.dispatch_table, the object's __reduce_ex__ method,
* or the object's __reduce__ method.
@@ -2717,6 +2712,11 @@
}
}
else {
+ if (PyType_IsSubtype(type, &PyType_Type)) {
+ res = save_global(self, args, NULL);
+ goto finally;
+ }
+
/* Check for a __reduce_ex__ method. */
__reduce__ = PyObject_GetAttr(args, __reduce_ex___str);
if (__reduce__ != NULL) {