Issue #7689: Allow pickling of dynamically created classes when their
metaclass is registered with copyreg.  Patch by Nicolas M. ThiƩry and
Craig Citro.
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index c2ed0d2..a22acc0 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -121,6 +121,19 @@
 class use_metaclass(object, metaclass=metaclass):
     pass
 
+class pickling_metaclass(type):
+    def __eq__(self, other):
+        return (type(self) == type(other) and
+                self.reduce_args == other.reduce_args)
+
+    def __reduce__(self):
+        return (create_dynamic_class, self.reduce_args)
+
+def create_dynamic_class(name, bases):
+    result = pickling_metaclass(name, bases, dict())
+    result.reduce_args = (name, bases)
+    return result
+
 # DATA0 .. DATA2 are the pickles we expect under the various protocols, for
 # the object returned by create_data().
 
@@ -695,6 +708,14 @@
             b = self.loads(s)
             self.assertEqual(a.__class__, b.__class__)
 
+    def test_dynamic_class(self):
+        a = create_dynamic_class("my_dynamic_class", (object,))
+        copyreg.pickle(pickling_metaclass, pickling_metaclass.__reduce__)
+        for proto in protocols:
+            s = self.dumps(a, proto)
+            b = self.loads(s)
+            self.assertEqual(a, b)
+
     def test_structseq(self):
         import time
         import os