Issue 1145: Allow str.join to join non-string types (as per PEP 3100) (original) (raw)

Created on 2007-09-11 11:41 by thomaslee, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
join-autostr.patch thomaslee,2007-09-11 11:41
join-autostr-r2.patch thomaslee,2007-09-13 09:35
Messages (10)
msg55820 - (view) Author: Thomas Lee (thomaslee) (Python committer) 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) (Python committer) 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) * (Python committer) 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) * (Python committer) 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) (Python committer) 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) (Python committer) 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) * (Python committer) 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) * (Python committer) 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) (Python committer) 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) * (Python committer) Date: 2007-09-27 18:01
Patience? :-) Seriously, I'd lost track of this. It's now submitted: Committed revision 58276.
History
Date User Action Args
2022-04-11 14:56:26 admin set github: 45486
2007-09-27 18:13:54 gvanrossum set status: open -> closedresolution: accepted
2007-09-27 18:01:45 gvanrossum set messages: +
2007-09-27 16:09:50 thomaslee set messages: +
2007-09-14 19:33:58 gvanrossum set messages: +
2007-09-13 19:58:00 georg.brandl set nosy: + georg.brandlmessages: +
2007-09-13 09:35:24 thomaslee set files: + join-autostr-r2.patchmessages: +
2007-09-13 07:29:43 thomaslee set messages: +
2007-09-12 19:45:13 gvanrossum set messages: +
2007-09-12 19:13:30 gvanrossum set assignee: gvanrossummessages: + nosy: + gvanrossum
2007-09-11 11:44:40 loewis set keywords: + patch
2007-09-11 11:42:58 thomaslee set messages: +
2007-09-11 11:41:15 thomaslee create