[pypy-commit] pypy py3k: fix test_range_indexing, when we use a too big negative index

antocuni noreply at buildbot.pypy.org
Fri Feb 24 20:13:36 CET 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r52880:4500a6d2fe49
Date: 2012-02-24 20:00 +0100
http://bitbucket.org/pypy/pypy/changeset/4500a6d2fe49/

Log:	fix test_range_indexing, when we use a too big negative index

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
@@ -325,9 +325,11 @@
         return space.add(self.w_start, space.mul(w_index, self.w_step))
         
     def _compute_item(self, space, w_index):
-        if space.is_true(space.lt(w_index, space.newint(0))):
+        w_zero = space.newint(0)
+        if space.is_true(space.lt(w_index, w_zero)):
             w_index = space.add(w_index, self.w_length)
-        if space.is_true(space.ge(w_index, self.w_length)):
+        if (space.is_true(space.ge(w_index, self.w_length)) or
+            space.is_true(space.lt(w_index, w_zero))):
             raise OperationError(space.w_IndexError, space.wrap(
                     "range object index out of range"))
         return self._compute_item0(space, w_index)


More information about the pypy-commit mailing list