summaryrefslogtreecommitdiffstats
path: root/Lib/pickle.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-12-19 16:55:02 (GMT)
committerGuido van Rossum <guido@python.org>2001-12-19 16:55:02 (GMT)
commitf048a8f6d79173cc1da1bf12c60ae06fea36762c (patch)
tree8010b1cdebbe8d725d689509be7a3082285c0dd9 /Lib/pickle.py
parent5935ff07beb0ed2b37dc7a85f04861122eaa5a9a (diff)
downloadcpython-f048a8f6d79173cc1da1bf12c60ae06fea36762c.zip
cpython-f048a8f6d79173cc1da1bf12c60ae06fea36762c.tar.gz
cpython-f048a8f6d79173cc1da1bf12c60ae06fea36762c.tar.bz2
Pickler.save(): Fix for SF bug #494904: Cannot pickle a class with a
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().
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r--Lib/pickle.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 8a07925..4cc6629 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -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)