diff options
| author | Guido van Rossum <guido@python.org> | 2001-12-19 16:56:54 +0000 |
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 2001-12-19 16:56:54 +0000 |
| commit | a22d50004f739e4c8a4d3748605ec09a85f4bff4 (patch) | |
| tree | 4132f53efe4160887184d4ab86f1e9e23ab9286a /Modules | |
| parent | cef0b49da1f60c7cfa30537a9e1ae6e411fe91e5 (diff) | |
| download | cpython-a22d50004f739e4c8a4d3748605ec09a85f4bff4.tar.gz | |
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 ob_type
is a subclass of PyType_Type, should be pickled the same as new-style
classes (objects whose ob_type is PyType_Type). This can't be done
through the existing dispatch switches, and the __reduce__ trick
doesn't work for these, since it finds the unbound __reduce__ for
instances of the class (inherited from PyBaseObject_Type). So check
explicitly using PyType_IsSubtype().
Diffstat (limited to 'Modules')
| -rw-r--r-- | Modules/cPickle.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Modules/cPickle.c b/Modules/cPickle.c index 425ff10bb0..a4943ce821 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -1990,6 +1990,11 @@ 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; |
