cpython: 760ac320fa3d (original) (raw)

Mercurial > cpython

changeset 72639:760ac320fa3d 3.2

Issue #7689: Allow pickling of dynamically created classes when their metaclass is registered with copyreg. Patch by Nicolas M. Thiéry and Craig Citro. [#7689]

Antoine Pitrou solipsis@pitrou.net
date Tue, 04 Oct 2011 09:23:04 +0200
parents d05350c14e77
children 46c026a5ccb9 bf39434dd506
files Lib/pickle.py Lib/test/pickletester.py Misc/ACKS Misc/NEWS Modules/_pickle.c
diffstat 5 files changed, 40 insertions(+), 13 deletions(-)[+] [-] Lib/pickle.py 18 Lib/test/pickletester.py 21 Misc/ACKS 2 Misc/NEWS 4 Modules/_pickle.c 8

line wrap: on

line diff

--- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -299,20 +299,20 @@ class _Pickler: f(self, obj) # Call unbound method with explicit self return

- # Check copyreg.dispatch_table reduce = dispatch_table.get(t) if reduce: rv = reduce(obj) else:

+ # Check for a reduce_ex method, fall back to reduce reduce = getattr(obj, "reduce_ex", None) if reduce:

--- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -121,6 +121,19 @@ class metaclass(type): class use_metaclass(object, metaclass=metaclass): pass +class pickling_metaclass(type):

+

+ +def create_dynamic_class(name, bases):

+

DATA0 .. DATA2 are the pickles we expect under the various protocols, for

the object returned by create_data().

@@ -695,6 +708,14 @@ class AbstractPickleTests(unittest.TestC b = self.loads(s) self.assertEqual(a.class, b.class)

+ def test_structseq(self): import time import os

--- a/Misc/ACKS +++ b/Misc/ACKS @@ -164,6 +164,7 @@ Anders Chrigström Tom Christiansen Vadim Chugunov David Cinege +Craig Citro Mike Clarkson Andrew Clegg Brad Clements @@ -881,6 +882,7 @@ Anatoly Techtonik Mikhail Terekhov Richard M. Tew Tobias Thelen +Nicolas M. Thiéry James Thomas Robin Thomas Stephen Thorne

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -36,6 +36,10 @@ Core and Builtins Library ------- +- Issue #7689: Allow pickling of dynamically created classes when their

--- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -3141,10 +3141,6 @@ save(PicklerObject *self, PyObject *obj, status = save_global(self, obj, NULL); goto done; }

/* XXX: This part needs some unit tests. */ @@ -3163,6 +3159,10 @@ save(PicklerObject *self, PyObject *obj, Py_INCREF(obj); reduce_value = _Pickler_FastCall(self, reduce_func, obj); }