diff options
author | Guido van Rossum <guido@python.org> | 2007-09-27 18:01:22 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-09-27 18:01:22 (GMT) |
commit | f1044293fa36667b5ba11fbc7acac21a03b82710 (patch) | |
tree | 41aac1b32323f1ae889d88c097157d330dc1aff7 /Objects | |
parent | 4e02c503e789337b07cc14ece3f5adbf23732c89 (diff) | |
download | cpython-f1044293fa36667b5ba11fbc7acac21a03b82710.zip cpython-f1044293fa36667b5ba11fbc7acac21a03b82710.tar.gz cpython-f1044293fa36667b5ba11fbc7acac21a03b82710.tar.bz2 |
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).
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 20 |
1 files changed, 13 insertions, 7 deletions
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 @@ 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. */ |