Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r88896:5e2bfa42f8f6
Date: 2016-12-06 11:28 +0100
http://bitbucket.org/pypy/pypy/changeset/5e2bfa42f8f6/

Log:    CPython issue #25718

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
@@ -1711,8 +1711,17 @@
 
     def reduce_w(self):
         space = self.space
+        w_func = space.w_None if self.w_func is None else self.w_func
+        if self.w_total is space.w_None:      # :-(
+            w_it = W_Chain(space, space.iter(space.newlist([
+                                     space.newtuple([self.w_total]),
+                                     self.w_iterable])))
+            w_it = space.call_function(space.type(self),
+                           w_it, w_func)
+            return space.newtuple([space.gettypefor(W_ISlice),
+                                   space.newtuple([w_it, space.wrap(1),
+                                                   space.w_None])])
         w_total = space.w_None if self.w_total is None else self.w_total
-        w_func = space.w_None if self.w_func is None else self.w_func
         return space.newtuple([space.gettypefor(W_Accumulate),
                                space.newtuple([self.w_iterable, w_func]), 
w_total])
 
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
@@ -90,7 +90,7 @@
 
     def test_repeat_len(self):
         import itertools
-        import operator
+        import _operator as operator
 
         r = itertools.repeat('a', 15)
         next(r)
@@ -329,7 +329,8 @@
             assert next(it) == x
 
     def test_starmap(self):
-        import itertools, operator
+        import itertools
+        import _operator as operator
 
         it = itertools.starmap(operator.add, [])
         raises(StopIteration, next, it)
@@ -1070,7 +1071,7 @@
         from itertools import accumulate
         from decimal import Decimal
         from fractions import Fraction
-        import operator
+        import _operator as operator
         expected = [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]
         # one positional arg
         assert list(accumulate(range(10))) == expected
@@ -1105,3 +1106,14 @@
         a = accumulate(it)
         a.__setstate__(20)
         assert a.__reduce__() == (accumulate, (it, None), 20)
+
+    def test_accumulate_reduce_corner_case(self):
+        from itertools import accumulate
+        import _operator as operator
+        it = iter([None, None, None])
+        a = accumulate(it, operator.is_)
+        next(a)
+        x1, x2 = a.__reduce__()
+        b = x1(*x2)
+        res = list(b)
+        assert res == [True, False]
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to