Author: Hakan Ardo <[email protected]>
Branch: step-one-xrange
Changeset: r55024:b856cc02e0bd
Date: 2012-05-10 07:44 +0200
http://bitbucket.org/pypy/pypy/changeset/b856cc02e0bd/
Log: pickle support
diff --git a/pypy/module/__builtin__/functional.py
b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -422,6 +422,9 @@
return self.space.wrap(self.remaining)
def descr_reduce(self):
+ return self.reduce(self.remaining)
+
+ def reduce(self, remaining):
from pypy.interpreter.mixedmodule import MixedModule
space = self.space
w_mod = space.getbuiltinmodule('_pickle_support')
@@ -430,7 +433,7 @@
w = space.wrap
nt = space.newtuple
- tup = [w(self.current), w(self.remaining), w(self.step)]
+ tup = [w(self.current), w(remaining), w(self.step)]
return nt([new_inst, nt(tup)])
W_XRangeIterator.typedef = TypeDef("rangeiterator",
@@ -454,6 +457,10 @@
self.current = item + 1
return self.space.wrap(item)
raise OperationError(self.space.w_StopIteration, self.space.w_None)
+
+ def descr_reduce(self):
+ return self.reduce(self.stop - self.current)
+
W_XRangeStepOneIterator.typedef = TypeDef("xrangesteponeiterator",
diff --git a/pypy/module/__builtin__/test/test_functional.py
b/pypy/module/__builtin__/test/test_functional.py
--- a/pypy/module/__builtin__/test/test_functional.py
+++ b/pypy/module/__builtin__/test/test_functional.py
@@ -164,6 +164,20 @@
y = callable(*args)
assert list(y) == list(x)
+ def test_xrange_iter_reduce(self):
+ x = iter(xrange(2, 9, 3))
+ x.next()
+ callable, args = x.__reduce__()
+ y = callable(*args)
+ assert list(y) == list(x)
+
+ def test_xrange_iter_reduce_one(self):
+ x = iter(xrange(2, 9))
+ x.next()
+ callable, args = x.__reduce__()
+ y = callable(*args)
+ assert list(y) == list(x)
+
class AppTestReversed:
def test_reversed(self):
r = reversed("hello")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit