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).
This commit is contained in:
Guido van Rossum 2007-09-27 18:01:22 +00:00
parent 4e02c503e7
commit f1044293fa
5 changed files with 28 additions and 16 deletions

View file

@ -5412,14 +5412,20 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
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. */