Commits

Alex Gaynor committed bf69a76

Fixed the exception raises in a bound-error case.

Comments (0)

Files changed (2)

pypy/module/micronumpy/numarray.py

 
     @unwrap_spec(item=int)
     def descr_getitem(self, space, item):
+        if item >= self.size:
+            raise operationerrfmt(space.w_IndexError,
+              '%d above array size', item)
         if item < 0:
-            raise operationerrfmt(space.w_TypeError,
+            item += self.size
+        if item < 0:
+            raise operationerrfmt(space.w_IndexError,
               '%d below zero', item)
-        if item >= self.size:
-            raise operationerrfmt(space.w_TypeError,
-              '%d above array size', item)
         return space.wrap(self.storage[item])
 
     @unwrap_spec(item=int, value=float)

pypy/module/micronumpy/test/test_numpy.py

     def test_getitem(self):
         from numpy import array
         a = array(range(5))
-        raises(TypeError, "a[5]")
+        raises(IndexError, "a[5]")
         a = a + a
-        raises(TypeError, "a[5]")
+        raises(IndexError, "a[5]")
+        assert a[-1] == 8
+        raises(IndexError, "a[-6]")
 
     def test_add(self):
         from numpy import array