]> granicus.if.org Git - python/commitdiff
Issue #6846: bytearray.pop was returning ints in the range [-128, 128)
authorMark Dickinson <dickinsm@gmail.com>
Sun, 6 Sep 2009 10:03:31 +0000 (10:03 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sun, 6 Sep 2009 10:03:31 +0000 (10:03 +0000)
instead of [0, 256).  Thanks Hagen Fürstenau for the report and fix.

Lib/test/test_bytes.py
Misc/NEWS
Objects/bytearrayobject.c

index ee4804f20226e5eec18a32c618ccf14d09e2e857..615c9557503c46441b3b0f8a7e3c73ac276d14b7 100644 (file)
@@ -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())
index 07f90f139bdc6710061e3e98bebb603e890ee2f0..739726cfbbb205b0c6889a33169bb8a9d19d9714 100644 (file)
--- 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
index 27b41bbf49d2942896258358847a8e7db5b4cf93..4105fa2cfaed1528df0cc4060f4669d3b236ef40 100644 (file)
@@ -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__,