Author: David Schneider <david.schnei...@picle.org>
Branch: 
Changeset: r63213:994b5a29d2cd
Date: 2013-04-10 22:47 +0200
http://bitbucket.org/pypy/pypy/changeset/994b5a29d2cd/

Log:    merge heads

diff --git a/lib_pypy/_functools.py b/lib_pypy/_functools.py
--- a/lib_pypy/_functools.py
+++ b/lib_pypy/_functools.py
@@ -20,3 +20,16 @@
         if self.keywords is not None:
             fkeywords = dict(self.keywords, **fkeywords)
         return self.func(*(self.args + fargs), **fkeywords)
+
+    def __reduce__(self):
+        d = dict((k, v) for k, v in self.__dict__.iteritems() if k not in
+                ('func', 'args', 'keywords'))
+        if len(d) == 0:
+            d = None
+        return (type(self), (self.func,),
+                (self.func, self.args, self.keywords, d))
+
+    def __setstate__(self, state):
+        self.func, self.args, self.keywords, d = state
+        if d is not None:
+            self.__dict__.update(d)
diff --git a/pypy/module/test_lib_pypy/test_functools.py 
b/pypy/module/test_lib_pypy/test_functools.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/test_lib_pypy/test_functools.py
@@ -0,0 +1,19 @@
+from lib_pypy import _functools
+
+def test_partial_reduce():
+    partial = _functools.partial(test_partial_reduce)
+    state = partial.__reduce__()
+    assert state == (type(partial), (test_partial_reduce,),
+                     (test_partial_reduce, (), None, None))
+
+def test_partial_setstate():
+    partial = _functools.partial(object)
+    partial.__setstate__([test_partial_setstate, (), None, None])
+    assert partial.func == test_partial_setstate
+
+def test_partial_pickle():
+    import pickle
+    partial1 = _functools.partial(test_partial_pickle)
+    string = pickle.dumps(partial1)
+    partial2 = pickle.loads(string)
+    assert partial1.func == partial2.func
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to