Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,11 @@ def test_bytearray_translate(self):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:meth:`bytearray.extend` now correctly handles errors that arise during iteration.
Patch by Brandt Bucher.
4 changes: 4 additions & 0 deletions Objects/bytearrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
}
Py_DECREF(bytearray_obj);

if (PyErr_Occurred()) {
return NULL;
}

Py_RETURN_NONE;
}

Expand Down