[pypy-commit] pypy py3.5: Mirror CPython classmethod __reduce__

exarkun pypy.commits at gmail.com
Fri Aug 11 16:42:23 EDT 2017


Author: Jean-Paul Calderone <exarkun at twistedmatrix.com>
Branch: py3.5
Changeset: r92128:d5f42df20932
Date: 2017-08-11 16:17 -0400
http://bitbucket.org/pypy/pypy/changeset/d5f42df20932/

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__


More information about the pypy-commit mailing list