Skip to content

Commit 2a7d596

Browse files
brandtbucherserhiy-storchaka
authored andcommitted
bpo-37417: Fix error handling in bytearray.extend. (GH-14407)
1 parent 5150d32 commit 2a7d596

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

Lib/test/test_builtin.py

+5
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,11 @@ def test_bytearray_translate(self):
15921592
self.assertRaises(ValueError, x.translate, b"1", 1)
15931593
self.assertRaises(TypeError, x.translate, b"1"*256, 1)
15941594

1595+
def test_bytearray_extend_error(self):
1596+
array = bytearray()
1597+
bad_iter = map(int, "X")
1598+
self.assertRaises(ValueError, array.extend, bad_iter)
1599+
15951600
def test_construct_singletons(self):
15961601
for const in None, Ellipsis, NotImplemented:
15971602
tp = type(const)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:meth:`bytearray.extend` now correctly handles errors that arise during iteration.
2+
Patch by Brandt Bucher.

Objects/bytearrayobject.c

+4
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
16981698
}
16991699
Py_DECREF(bytearray_obj);
17001700

1701+
if (PyErr_Occurred()) {
1702+
return NULL;
1703+
}
1704+
17011705
Py_RETURN_NONE;
17021706
}
17031707

0 commit comments

Comments
 (0)