diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index caea9094b18..dd01b936b26 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -716,6 +716,8 @@ class ByteArrayTest(BaseBytesTest): self.assertEqual(b.pop(-2), ord('r')) self.assertRaises(IndexError, lambda: b.pop(10)) self.assertRaises(OverflowError, lambda: bytearray().pop()) + # test for issue #6846 + self.assertEqual(bytearray(b'\xff').pop(), 0xff) def test_nosort(self): self.assertRaises(AttributeError, lambda: bytearray().sort()) diff --git a/Misc/NEWS b/Misc/NEWS index 6e6aa540cfa..7243eb96ddf 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 3.2 Alpha 1? Core and Builtins ----------------- +- Issue #6846: Fix bug where bytearray.pop() returns negative integers. + - Issue #6750: A text file opened with io.open() could duplicate its output when writing from multiple threads at the same time. diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index f3d569712f6..f8f9469f5f4 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2705,7 +2705,7 @@ bytearray_pop(PyByteArrayObject *self, PyObject *args) if (PyByteArray_Resize((PyObject *)self, n - 1) < 0) return NULL; - return PyLong_FromLong(value); + return PyLong_FromLong((unsigned char)value); } PyDoc_STRVAR(remove__doc__,