Patch # 1145 by Thomas Lee:
str.join(...) now applies str() to the sequence elements if they're
not strings alraedy, except for bytes, which still raise TypeError
(for the same reasons why ""==b"" raises it).
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index c40f0be..ad78492 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -5412,14 +5412,20 @@
item = PySequence_Fast_GET_ITEM(fseq, i);
/* Convert item to Unicode. */
- if (! PyUnicode_Check(item) && ! PyString_Check(item)) {
- PyErr_Format(PyExc_TypeError,
- "sequence item %zd: expected string or Unicode,"
- " %.80s found",
- i, Py_Type(item)->tp_name);
- goto onError;
+ if (!PyString_Check(item) && !PyUnicode_Check(item))
+ {
+ if (PyBytes_Check(item))
+ {
+ PyErr_Format(PyExc_TypeError,
+ "sequence item %d: join() will not operate on "
+ "bytes objects", i);
+ goto onError;
+ }
+ item = PyObject_Unicode(item);
}
- item = PyUnicode_FromObject(item);
+ else
+ item = PyUnicode_FromObject(item);
+
if (item == NULL)
goto onError;
/* We own a reference to item from here on. */