[pypy-svn] r59111 - in pypy/trunk/pypy/objspace/std: . test
arigo at codespeak.net
arigo at codespeak.net
Wed Oct 15 17:13:24 CEST 2008
Author: arigo
Date: Wed Oct 15 17:13:23 2008
New Revision: 59111
Modified:
pypy/trunk/pypy/objspace/std/sliceobject.py
pypy/trunk/pypy/objspace/std/test/test_sliceobject.py
Log:
(antocuni, arigo)
Fix an issue shown by (e.g.) test_iterobject.py.
The fix is to be as sane as possible in the return value
of normalize_simple_slice().
Modified: pypy/trunk/pypy/objspace/std/sliceobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/sliceobject.py (original)
+++ pypy/trunk/pypy/objspace/std/sliceobject.py Wed Oct 15 17:13:23 2008
@@ -82,18 +82,18 @@
def normalize_simple_slice(space, length, w_start, w_stop):
"""Helper for the {get,set,del}slice multimethod implementations."""
# this returns a pair (start, stop) which is usable for slicing
- # a sequence of the given length in an RPython-friendly way, i.e.
- # guaranteeing that:
- # * 0 <= start <= length
- # * start <= stop
+ # a sequence of the given length in the most friendly way, i.e.
+ # guaranteeing that 0 <= start <= stop <= length.
start = space.int_w(w_start)
stop = space.int_w(w_stop)
- if start > length:
- start = length
if start < 0:
start = 0
if stop < start:
stop = start
+ if stop > length:
+ stop = length
+ if start > length:
+ start = length
return start, stop
Modified: pypy/trunk/pypy/objspace/std/test/test_sliceobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_sliceobject.py (original)
+++ pypy/trunk/pypy/objspace/std/test/test_sliceobject.py Wed Oct 15 17:13:23 2008
@@ -37,8 +37,7 @@
for stop in range(-2*length-2, 2*length+3):
mystart, mystop = normalize_simple_slice(space, length,
w(start), w(stop))
- assert 0 <= mystart <= length
- assert mystart <= mystop
+ assert 0 <= mystart <= mystop <= length
assert (getslice(length, start, stop) ==
getslice(length, mystart, mystop))
More information about the Pypy-commit
mailing list