mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-37417: Fix error handling in bytearray.extend. (GH-14407)
(cherry picked from commit 2a7d596f27
)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
This commit is contained in:
parent
bdbd5e895d
commit
5c4ce3e2fa
3 changed files with 11 additions and 0 deletions
|
@ -1592,6 +1592,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)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
:meth:`bytearray.extend` now correctly handles errors that arise during iteration.
|
||||
Patch by Brandt Bucher.
|
|
@ -1698,6 +1698,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
|
|||
}
|
||||
Py_DECREF(bytearray_obj);
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue