Skip to content

Commit f048a8f

Browse files
committed
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().
1 parent 5935ff0 commit f048a8f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Lib/pickle.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ def save(self, object, pers_save = 0):
163163
try:
164164
f = self.dispatch[t]
165165
except KeyError:
166+
if issubclass(t, TypeType):
167+
self.save_global(object)
168+
return
169+
166170
pid = self.inst_persistent_id(object)
167171
if pid is not None:
168172
self.save_pers(pid)

0 commit comments

Comments
 (0)