[pypy-svn] r77764 - in pypy/branch/fast-forward/pypy/objspace/std: . test
afa at codespeak.net
afa at codespeak.net
Sun Oct 10 20:16:31 CEST 2010
Author: afa
Date: Sun Oct 10 20:16:29 2010
New Revision: 77764
Modified:
pypy/branch/fast-forward/pypy/objspace/std/slicetype.py
pypy/branch/fast-forward/pypy/objspace/std/test/test_sliceobject.py
Log:
Make slices picklable
Modified: pypy/branch/fast-forward/pypy/objspace/std/slicetype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/slicetype.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/slicetype.py Sun Oct 10 20:16:29 2010
@@ -72,6 +72,15 @@
descr__new__.unwrap_spec = [baseobjspace.ObjSpace, baseobjspace.W_Root,
'args_w']
+def descr__reduce__(space, w_self):
+ return space.newtuple([
+ space.type(w_self),
+ space.newtuple([w_self.w_start,
+ w_self.w_stop,
+ w_self.w_step]),
+ ])
+descr__reduce__.unwrap_spec = [baseobjspace.ObjSpace, baseobjspace.W_Root]
+
# ____________________________________________________________
def slicewprop(name):
@@ -90,6 +99,7 @@
Create a slice object. This is used for extended slicing (e.g. a[0:10:2]).''',
__new__ = gateway.interp2app(descr__new__),
__hash__ = None,
+ __reduce__ = gateway.interp2app(descr__reduce__),
start = slicewprop('w_start'),
stop = slicewprop('w_stop'),
step = slicewprop('w_step'),
Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_sliceobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_sliceobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_sliceobject.py Sun Oct 10 20:16:29 2010
@@ -93,3 +93,6 @@
assert stop == 1000
assert step >= 1000
raises(OverflowError, "slice(0, 1000, 1).indices(2 ** 100)")
+
+ def test_reduce(self):
+ assert slice(1, 2, 3).__reduce__() == (slice, (1, 2, 3))
More information about the Pypy-commit
mailing list