From: Eli Bendersky Date: Fri, 4 Mar 2011 04:55:25 +0000 (+0000) Subject: Issue #11386: Fixed the exception thrown by bytearray.pop() for empty bytearrays X-Git-Tag: v3.3.0a1~2997 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1bc4f193d8419405e9b34f5e8dcbeb2ee5a15fc9;p=python Issue #11386: Fixed the exception thrown by bytearray.pop() for empty bytearrays --- diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index a6f1826a0b..0b70c3a35c 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index c0894127f9..876afdd08e 100644 --- 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 ------- diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index b4194827fe..0c80f674a2 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -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)