summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorJay Ting <65202977+jayasting98@users.noreply.github.com>2024-02-24 23:34:45 (GMT)
committerGitHub <noreply@github.com>2024-02-24 23:34:45 (GMT)
commit948acd6ed856251dc5889cc34cf7a58210c4f9a9 (patch)
treeff3492e2fe56bdf4d04113535eeda3d1e60f7362 /Objects
parente3dedeae7abbeda0cb3f1d872ebbb914635d64f2 (diff)
downloadcpython-948acd6ed856251dc5889cc34cf7a58210c4f9a9.zip
cpython-948acd6ed856251dc5889cc34cf7a58210c4f9a9.tar.gz
cpython-948acd6ed856251dc5889cc34cf7a58210c4f9a9.tar.bz2
gh-115323: Add meaningful error message for using bytearray.extend with str (#115332)
Perform str check after TypeError is raised --------- Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bytearrayobject.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index acc59b9..5e3b3af 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1729,6 +1729,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
while ((item = PyIter_Next(it)) != NULL) {
if (! _getbytevalue(item, &value)) {
+ if (PyErr_ExceptionMatches(PyExc_TypeError) && PyUnicode_Check(iterable_of_ints)) {
+ PyErr_Format(PyExc_TypeError,
+ "expected iterable of integers; got: 'str'");
+ }
Py_DECREF(item);
Py_DECREF(it);
Py_DECREF(bytearray_obj);