From c8a7c7c3b9c28dd2c0f9b81d807f8c7f60cb0924 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sun, 6 Sep 2009 10:03:31 +0000 Subject: =?UTF-8?q?Issue=20#6846:=20bytearray.pop=20was=20returning=20ints?= =?UTF-8?q?=20in=20the=20range=20[-128,=20128)=20instead=20of=20[0,=20256)?= =?UTF-8?q?.=20=20Thanks=20Hagen=20F=C3=BCrstenau=20for=20the=20report=20a?= =?UTF-8?q?nd=20fix.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/test/test_bytes.py | 2 ++ Misc/NEWS | 2 ++ Objects/bytearrayobject.c | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index ee4804f..615c955 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -690,6 +690,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 07f90f1..739726c 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 2.7 alpha 1 Core and Builtins ----------------- +- Issue #6846: Fix bug where bytearray.pop() returns negative integers. + - classmethod no longer checks if its argument is callable. - Issue #6750: A text file opened with io.open() could duplicate its output diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 27b41bb..4105fa2 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2773,7 +2773,7 @@ bytearray_pop(PyByteArrayObject *self, PyObject *args) if (PyByteArray_Resize((PyObject *)self, n - 1) < 0) return NULL; - return PyInt_FromLong(value); + return PyInt_FromLong((unsigned char)value); } PyDoc_STRVAR(remove__doc__, -- cgit v0.12