Skip to content

Commit 004e03f

Browse files
bpo-29116: Improve error message for concatenating str with non-str. (#710)
1 parent 80ec836 commit 004e03f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Objects/unicodeobject.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11282,7 +11282,16 @@ PyUnicode_Concat(PyObject *left, PyObject *right)
1128211282
Py_UCS4 maxchar, maxchar2;
1128311283
Py_ssize_t left_len, right_len, new_len;
1128411284

11285-
if (ensure_unicode(left) < 0 || ensure_unicode(right) < 0)
11285+
if (ensure_unicode(left) < 0)
11286+
return NULL;
11287+
11288+
if (!PyUnicode_Check(right)) {
11289+
PyErr_Format(PyExc_TypeError,
11290+
"can only concatenate str (not \"%.200s\") to str",
11291+
right->ob_type->tp_name);
11292+
return NULL;
11293+
}
11294+
if (PyUnicode_READY(right) < 0)
1128611295
return NULL;
1128711296

1128811297
/* Shortcuts */

0 commit comments

Comments
 (0)