Commit 2a7d596f authored by Brandt Bucher's avatar Brandt Bucher Committed by Serhiy Storchaka

bpo-37417: Fix error handling in bytearray.extend. (GH-14407)

parent 5150d327
...@@ -1592,6 +1592,11 @@ class BuiltinTest(unittest.TestCase): ...@@ -1592,6 +1592,11 @@ class BuiltinTest(unittest.TestCase):
self.assertRaises(ValueError, x.translate, b"1", 1) self.assertRaises(ValueError, x.translate, b"1", 1)
self.assertRaises(TypeError, x.translate, b"1"*256, 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): def test_construct_singletons(self):
for const in None, Ellipsis, NotImplemented: for const in None, Ellipsis, NotImplemented:
tp = type(const) tp = type(const)
......
:meth:`bytearray.extend` now correctly handles errors that arise during iteration.
Patch by Brandt Bucher.
\ No newline at end of file
...@@ -1698,6 +1698,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints) ...@@ -1698,6 +1698,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
} }
Py_DECREF(bytearray_obj); Py_DECREF(bytearray_obj);
if (PyErr_Occurred()) {
return NULL;
}
Py_RETURN_NONE; Py_RETURN_NONE;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment