mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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:
parent
4e02c503e7
commit
f1044293fa
5 changed files with 28 additions and 16 deletions
|
@ -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. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue