[pypy-svn] r28586 - in pypy/dist/pypy/interpreter: . test
mwh at codespeak.net
mwh at codespeak.net
Fri Jun 9 15:15:20 CEST 2006
Author: mwh
Date: Fri Jun 9 15:15:18 2006
New Revision: 28586
Modified:
pypy/dist/pypy/interpreter/function.py
pypy/dist/pypy/interpreter/test/test_pickle.py
Log:
(mwh, pedronis)
Test + implementation for pickling builtin methods.
Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py (original)
+++ pypy/dist/pypy/interpreter/function.py Fri Jun 9 15:15:18 2006
@@ -404,12 +404,20 @@
def descr_method__reduce__(self, space):
from pypy.interpreter.mixedmodule import MixedModule
+ from pypy.interpreter.gateway import BuiltinCode
w_mod = space.getbuiltinmodule('_pickle_support')
mod = space.interp_w(MixedModule, w_mod)
new_inst = mod.get('method_new')
w = space.wrap
w_instance = self.w_instance or space.w_None
- if space.is_w( self.w_class, space.w_None ):
+ function = space.interpclass_w(self.w_function)
+ if isinstance(function, Function) and isinstance(function.code, BuiltinCode):
+ new_inst = mod.get('builtin_method_new')
+ if space.is_w(w_instance, space.w_None):
+ tup = [self.w_class, space.wrap(function.name)]
+ else:
+ tup = [w_instance, space.wrap(function.name)]
+ elif space.is_w( self.w_class, space.w_None ):
tup = [self.w_function, w_instance]
else:
tup = [self.w_function, w_instance, self.w_class]
Modified: pypy/dist/pypy/interpreter/test/test_pickle.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_pickle.py (original)
+++ pypy/dist/pypy/interpreter/test/test_pickle.py Fri Jun 9 15:15:18 2006
@@ -374,3 +374,21 @@
assert list(g1) == list(g2)
finally:
del sys.modules['mod']
+
+ def test_pickle_builtin_method(self):
+ import pickle
+
+ a_list = [1]
+ meth1 = a_list.append
+ pckl = pickle.dumps(meth1)
+ meth2 = pickle.loads(pckl)
+ meth1(1)
+ meth2(2)
+ assert a_list == [1, 1]
+ assert meth2.im_self == [1, 2]
+
+ unbound_meth = list.append
+ unbound_meth2 = pickle.loads(pickle.dumps(unbound_meth))
+ l = []
+ unbound_meth2(l, 1)
+ assert l == [1]
More information about the Pypy-commit
mailing list