Author: Omer Katz <[email protected]>
Branch: py3.3
Changeset: r80859:f070ee413b8a
Date: 2015-11-23 14:56 +0200
http://bitbucket.org/pypy/pypy/changeset/f070ee413b8a/

Log:    Implemented the __setstate__ method for accumulate.

diff --git a/pypy/module/itertools/interp_itertools.py 
b/pypy/module/itertools/interp_itertools.py
--- a/pypy/module/itertools/interp_itertools.py
+++ b/pypy/module/itertools/interp_itertools.py
@@ -1224,6 +1224,10 @@
             return space.newtuple([space.gettypefor(W_Accumulate),
                                    space.newtuple([self.w_iterable, w_func]), 
w_total])
 
+    def setstate_w(self, w_total):
+        space = self.space
+        self.w_total = w_total
+
 def W_Accumulate__new__(space, w_subtype, w_iterable, w_func=None):
     r = space.allocate_instance(W_Accumulate, w_subtype)
     r.__init__(space, space.iter(w_iterable), w_func)
@@ -1234,6 +1238,7 @@
     __iter__ = interp2app(W_Accumulate.iter_w),
     __next__ = interp2app(W_Accumulate.next_w),
     __reduce__ = interp2app(W_Accumulate.reduce_w),
+    __setstate__ = interp2app(W_Accumulate.setstate_w),
     __doc__  = """\
 "accumulate(iterable) --> accumulate object
 
diff --git a/pypy/module/itertools/test/test_itertools.py 
b/pypy/module/itertools/test/test_itertools.py
--- a/pypy/module/itertools/test/test_itertools.py
+++ b/pypy/module/itertools/test/test_itertools.py
@@ -1004,3 +1004,8 @@
         next(a)
         next(a)
         assert a.__reduce__() == (accumulate, (it, None), 60)
+
+        it = iter([10, 50, 150])
+        a = accumulate(it)
+        a.__setstate__(20)
+        assert a.__reduce__() == (accumulate, (it, None), 20)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to