]> granicus.if.org Git - python/commitdiff
Pickler.save(): Fix for SF bug #494904: Cannot pickle a class with a
authorGuido van Rossum <guido@python.org>
Wed, 19 Dec 2001 16:55:02 +0000 (16:55 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 19 Dec 2001 16:55:02 +0000 (16:55 +0000)
metaclass, reported by Dan Parisien.

Objects that are instances of custom metaclasses, i.e. whose class is
a subclass of 'type', should be pickled the same as new-style classes
(objects whose class is 'type').  This can't be done through a
dispatch table entry, and the __reduce__ trick doesn't work for these,
since it finds the unbound __reduce__ for instances of the class
(inherited from 'object').  So check explicitly using issubclass().

Lib/pickle.py

index 8a079255f13052ff975e3d1f7a08278c01c6de2e..4cc6629d532e97304b382d9bf3937b7c3e477a06 100644 (file)
@@ -163,6 +163,10 @@ class Pickler:
         try:
             f = self.dispatch[t]
         except KeyError:
+            if issubclass(t, TypeType):
+                self.save_global(object)
+                return
+
             pid = self.inst_persistent_id(object)
             if pid is not None:
                 self.save_pers(pid)