]> granicus.if.org Git - python/commitdiff
Issue #11386: Fixed the exception thrown by bytearray.pop() for empty bytearrays
authorEli Bendersky <eliben@gmail.com>
Fri, 4 Mar 2011 04:55:25 +0000 (04:55 +0000)
committerEli Bendersky <eliben@gmail.com>
Fri, 4 Mar 2011 04:55:25 +0000 (04:55 +0000)
Lib/test/test_bytes.py
Misc/NEWS
Objects/bytearrayobject.c

index a6f1826a0b9061fd0fe643a0eb5a5d37b8dfc9b3..0b70c3a35cdec44d5794e279aec115beb10a1eba 100644 (file)
@@ -790,7 +790,7 @@ class ByteArrayTest(BaseBytesTest):
         self.assertEqual(b.pop(0), ord('w'))
         self.assertEqual(b.pop(-2), ord('r'))
         self.assertRaises(IndexError, lambda: b.pop(10))
-        self.assertRaises(OverflowError, lambda: bytearray().pop())
+        self.assertRaises(IndexError, lambda: bytearray().pop())
         # test for issue #6846
         self.assertEqual(bytearray(b'\xff').pop(), 0xff)
 
index c0894127f9f9b057f40c2abcc62adfca2f33f785..876afdd08ef38e986f0e58e80db40efae8c3347b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -49,6 +49,9 @@ Core and Builtins
 
 - Issue #10516: New copy() and clear() methods for lists and bytearrays.
 
+- Issue #11386: bytearray.pop() now throws IndexError when the bytearray is
+  empty, instead of OverflowError.
+
 Library
 -------
 
index b4194827fe38796d952ff975936f85ee88d33789..0c80f674a2d42f66ab90f9317e65a35fd8178766 100644 (file)
@@ -2309,8 +2309,8 @@ bytearray_pop(PyByteArrayObject *self, PyObject *args)
         return NULL;
 
     if (n == 0) {
-        PyErr_SetString(PyExc_OverflowError,
-                        "cannot pop an empty bytearray");
+        PyErr_SetString(PyExc_IndexError,
+                        "pop from empty bytearray");
         return NULL;
     }
     if (where < 0)