]> granicus.if.org Git - python/commitdiff
bpo-29116: Improve error message for concatenating str with non-str. (#710)
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 19 Mar 2017 17:38:42 +0000 (19:38 +0200)
committerGitHub <noreply@github.com>
Sun, 19 Mar 2017 17:38:42 +0000 (19:38 +0200)
Objects/unicodeobject.c

index 503a59e1ef1336e44312cdfd3ab535ec88879dcd..1a696cc5c89ead6e078a8511d91d49bd877e0d78 100644 (file)
@@ -11282,7 +11282,16 @@ PyUnicode_Concat(PyObject *left, PyObject *right)
     Py_UCS4 maxchar, maxchar2;
     Py_ssize_t left_len, right_len, new_len;
 
-    if (ensure_unicode(left) < 0 || ensure_unicode(right) < 0)
+    if (ensure_unicode(left) < 0)
+        return NULL;
+
+    if (!PyUnicode_Check(right)) {
+        PyErr_Format(PyExc_TypeError,
+                     "can only concatenate str (not \"%.200s\") to str",
+                     right->ob_type->tp_name);
+        return NULL;
+    }
+    if (PyUnicode_READY(right) < 0)
         return NULL;
 
     /* Shortcuts */