mirror of
https://github.com/python/cpython.git
synced 2025-09-14 20:56:06 +00:00
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().
This commit is contained in:
parent
f048a8f6d7
commit
950dce6f01
1 changed files with 5 additions and 0 deletions
|
@ -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 (!pers_save && self->inst_pers_func) {
|
||||||
if ((tmp = save_pers(self, args, self->inst_pers_func)) != 0) {
|
if ((tmp = save_pers(self, args, self->inst_pers_func)) != 0) {
|
||||||
res = tmp;
|
res = tmp;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue