diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index 6b5ef365122..2026cdbde19 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -695,7 +695,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 bed3edcfa29..f1da92c1039 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -34,6 +34,9 @@ Core and Builtins float.__divmod__ with respect to signed zeros. -4.0 % 4.0 should be 0.0, not -0.0. +- 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 54ef3e7eab9..86093955d8b 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2355,8 +2355,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)