summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-06-26 19:23:19 (GMT)
committerGitHub <noreply@github.com>2019-06-26 19:23:19 (GMT)
commit7675bca4b56c532875d8bc6a7832e3c51d71278f (patch)
tree63c3f74d82ba76d92bf3e5e5b425c1db43751637
parent7b8a449d191a7ca5611ecd4ac598d0a9e05f6e0d (diff)
downloadcpython-7675bca4b56c532875d8bc6a7832e3c51d71278f.zip
cpython-7675bca4b56c532875d8bc6a7832e3c51d71278f.tar.gz
cpython-7675bca4b56c532875d8bc6a7832e3c51d71278f.tar.bz2
bpo-37417: Fix error handling in bytearray.extend. (GH-14407)
(cherry picked from commit 2a7d596f27b2342caf168a03c95ebf3b56e5dbbd) Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
-rw-r--r--Lib/test/test_builtin.py5
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2019-06-26-18-41-00.bpo-37417.VsZeHL.rst2
-rw-r--r--Objects/bytearrayobject.c4
3 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index c3f04ec..e0d2a69 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -1511,6 +1511,11 @@ class BuiltinTest(unittest.TestCase):
self.assertRaises(ValueError, x.translate, b"1", 1)
self.assertRaises(TypeError, x.translate, b"1"*256, 1)
+ def test_bytearray_extend_error(self):
+ array = bytearray()
+ bad_iter = map(int, "X")
+ self.assertRaises(ValueError, array.extend, bad_iter)
+
def test_construct_singletons(self):
for const in None, Ellipsis, NotImplemented:
tp = type(const)
diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-06-26-18-41-00.bpo-37417.VsZeHL.rst b/Misc/NEWS.d/next/Core and Builtins/2019-06-26-18-41-00.bpo-37417.VsZeHL.rst
new file mode 100644
index 0000000..f004631
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2019-06-26-18-41-00.bpo-37417.VsZeHL.rst
@@ -0,0 +1,2 @@
+:meth:`bytearray.extend` now correctly handles errors that arise during iteration.
+Patch by Brandt Bucher. \ No newline at end of file
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 8a0994f..41de28d 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1689,6 +1689,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
}
Py_DECREF(bytearray_obj);
+ if (PyErr_Occurred()) {
+ return NULL;
+ }
+
Py_RETURN_NONE;
}