msg55820 - (view) |
Author: Thomas Lee (thomaslee)  |
Date: 2007-09-11 11:41 |
The current implementation of str.join requires that the parameters passed to it be string/unicode values. A suggestion to allow it to accept parameters of any type came up in PEP 3100. Implemented for Unicode using the attached patch. It would be trivial to add this functionality to the old string object too, but I haven't been following the string to unicode discussion too closely and I'm unsure if the old string object will remain for too much longer. |
|
|
msg55821 - (view) |
Author: Thomas Lee (thomaslee)  |
Date: 2007-09-11 11:42 |
Oh and an example of usage: # before the patch ', '.join([str(x) for x in [1, 2, 3]]) # after the patch ', '.join([1, 2, 3]) |
|
|
msg55860 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2007-09-12 19:13 |
I like this, but the patch has problems: you don't error-check the return value from PyObject_Unicode() or PyUnicode_FromObject() (and why do you need the latter call anyway?) Also in the docstring I would reference str() instead of __str__(). There are also a few lines longer than 80 chars. |
|
|
msg55870 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2007-09-12 19:45 |
There's one additional issue. If any of the items is a bytes, the call should fail. |
|
|
msg55882 - (view) |
Author: Thomas Lee (thomaslee)  |
Date: 2007-09-13 07:29 |
Sure - I'll get onto that. Should have another patch up later tonight. |
|
|
msg55887 - (view) |
Author: Thomas Lee (thomaslee)  |
Date: 2007-09-13 09:35 |
Updated patch: * unneeded PyUnicode_FromObject call removed (I thought this was necessary, but the original author appears to be using it for an INCREF) * documentation now fits into 80 chars * return values from PyObject_Unicode and PyObject_FromObject checked * bytes() objects found in the sequence will raise a TypeError * removed redundant assertion and added the bytes case to test_unicode |
|
|
msg55898 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2007-09-13 19:58 |
Guido van Rossum schrieb: > Guido van Rossum added the comment: > > There's one additional issue. If any of the items is a bytes, the call > should fail. Should it really, even if the bytes is ascii-encodable? Georg |
|
|
msg55914 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2007-09-14 19:33 |
> Should it really, even if the bytes is ascii-encodable? Yes, really. We don't want to open up the same can of worms that made working with Unicode such a pain in 2.x. |
|
|
msg56167 - (view) |
Author: Thomas Lee (thomaslee)  |
Date: 2007-09-27 16:09 |
Is there anything else you need from me for this one Guido? |
|
|
msg56177 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2007-09-27 18:01 |
Patience? :-) Seriously, I'd lost track of this. It's now submitted: Committed revision 58276. |
|
|