[pypy-svn] r77766 - in pypy/branch/fast-forward/pypy/objspace/std: . test

afa at codespeak.net afa at codespeak.net
Sun Oct 10 21:16:47 CEST 2010


Author: afa
Date: Sun Oct 10 21:16:09 2010
New Revision: 77766

Modified:
   pypy/branch/fast-forward/pypy/objspace/std/sliceobject.py
   pypy/branch/fast-forward/pypy/objspace/std/test/test_sliceobject.py
Log:
cpython issue3004 slightly changed the behavior of slice.indices()


Modified: pypy/branch/fast-forward/pypy/objspace/std/sliceobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/sliceobject.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/sliceobject.py	Sun Oct 10 21:16:09 2010
@@ -59,9 +59,15 @@
             if stop < 0:
                 stop += length
                 if stop < 0:
-                    stop =-1
-            elif stop > length:
-                stop = length
+                    if step < 0:
+                        stop = -1
+                    else:
+                        stop = 0
+            elif stop >= length:
+                if step < 0:
+                    stop = length - 1
+                else:
+                    stop = length
         return start, stop, step
 
     def indices4(w_slice, space, length):

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 21:16:09 2010
@@ -60,7 +60,11 @@
         assert slice(4,11,2).indices(2) == (2, 2, 2)
         assert slice(11,4,-2).indices(28) == (11, 4, -2)
         assert slice(11,4,-2).indices(8) == (7, 4, -2)
-        assert slice(11,4,-2).indices(2) == (1, 2, -2)
+        assert slice(11,4,-2).indices(2) == (1, 1, -2)
+        assert slice(None, -9).indices(10) == (0, 1, 1)
+        assert slice(None, -10, -1).indices(10) == (9, 0, -1)
+        assert slice(None, 10, -1).indices(10) == (9, 9, -1)
+
 
     def test_repr(self):
         assert repr(slice(1, 2, 3)) == 'slice(1, 2, 3)'
@@ -85,7 +89,7 @@
 
     def test_long_indices(self):
         assert slice(-2 ** 100, 10, 1).indices(1000) == (0, 10, 1)
-        assert slice(-2 ** 200, -2 ** 100, 1).indices(1000) == (0, -1, 1)
+        assert slice(-2 ** 200, -2 ** 100, 1).indices(1000) == (0, 0, 1)
         assert slice(2 ** 100, 0, -1).indices(1000) == (999, 0, -1)
         assert slice(2 ** 100, -2 ** 100, -1).indices(1000) == (999, -1, -1)
         start, stop, step = slice(0, 1000, 2 ** 200).indices(1000)



More information about the Pypy-commit mailing list