Skip to content

Commit

Permalink
bpo-37417: Fix error handling in bytearray.extend. (pythonGH-14407)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher authored and serhiy-storchaka committed Jun 26, 2019
1 parent 5150d32 commit 2a7d596
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
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

0 comments on commit 2a7d596

Please sign in to comment.