[pypy-svn] r77737 - in pypy/branch/fast-forward/pypy/module/__builtin__: . test

afa at codespeak.net afa at codespeak.net
Sat Oct 9 00:00:04 CEST 2010


Author: afa
Date: Sat Oct  9 00:00:03 2010
New Revision: 77737

Modified:
   pypy/branch/fast-forward/pypy/module/__builtin__/functional.py
   pypy/branch/fast-forward/pypy/module/__builtin__/test/test_functional.py
Log:
xrange objects are now pickable


Modified: pypy/branch/fast-forward/pypy/module/__builtin__/functional.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/__builtin__/functional.py	(original)
+++ pypy/branch/fast-forward/pypy/module/__builtin__/functional.py	Sat Oct  9 00:00:03 2010
@@ -631,6 +631,15 @@
         return self.space.wrap(W_XRangeIterator(self.space, lastitem,
                                                 self.len, -self.step))
 
+    def descr_reduce(self):
+        space = self.space
+        return space.newtuple(
+            [space.type(self),
+             space.newtuple([space.wrap(self.start),
+                             space.wrap(self.start + self.len * self.step),
+                             space.wrap(self.step)])
+             ])
+
 def _toint(space, w_obj):
     # this also supports float arguments.  CPython still does, too.
     # needs a bit more thinking in general...
@@ -644,6 +653,7 @@
     __iter__         = interp2app(W_XRange.descr_iter),
     __len__          = interp2app(W_XRange.descr_len),
     __reversed__     = interp2app(W_XRange.descr_reversed),
+    __reduce__       = interp2app(W_XRange.descr_reduce),
 )
 
 class W_XRangeIterator(Wrappable):

Modified: pypy/branch/fast-forward/pypy/module/__builtin__/test/test_functional.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/__builtin__/test/test_functional.py	(original)
+++ pypy/branch/fast-forward/pypy/module/__builtin__/test/test_functional.py	Sat Oct  9 00:00:03 2010
@@ -158,6 +158,12 @@
        raises(OverflowError, xrange, 0, a)
        raises(OverflowError, xrange, 0, 1, a)
 
+   def test_xrange_reduce(self):
+      x = xrange(2, 9, 3)
+      callable, args = x.__reduce__()
+      y = callable(*args)
+      assert list(y) == list(x)
+
 class AppTestReversed:
    def test_reversed(self):
       r = reversed("hello")



More information about the Pypy-commit mailing list