Author: Jean-Paul Calderone <exar...@twistedmatrix.com>
Branch: 
Changeset: r92126:c38befdc824e
Date: 2017-08-11 16:17 -0400
http://bitbucket.org/pypy/pypy/changeset/c38befdc824e/

Log:    Mirror CPython classmethod __reduce__

        This makes classmethods pickleable and should fix lib-
        python/3/test_pickle.py.

diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -596,8 +596,9 @@
             new_inst = mod.get('builtin_method_new')
             tup = [w_instance, space.newtext(w_function.name)]
         else:
-            new_inst = mod.get('method_new')
-            tup = [self.w_function, w_instance]
+            w_builtins = space.getbuiltinmodule('builtins')
+            new_inst = space.getattr(w_builtins, space.newtext('getattr'))
+            tup = [w_instance, space.newtext(self.w_function.name)]
         return space.newtuple([new_inst, space.newtuple(tup)])
 
 
diff --git a/pypy/interpreter/test/test_function.py 
b/pypy/interpreter/test/test_function.py
--- a/pypy/interpreter/test/test_function.py
+++ b/pypy/interpreter/test/test_function.py
@@ -49,6 +49,15 @@
         assert f().__qualname__ == 'inner_global'
         assert f()().__qualname__ == 'inner_global.<locals>.inner_function2'
 
+    def test_classmethod_reduce(self):
+        class X(object):
+            @classmethod
+            def y(cls):
+                pass
+
+        f, args = X.y.__reduce__()
+        assert f(*args) == X.y
+
     def test_annotations(self):
         def f(): pass
         ann = f.__annotations__
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to