This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Allow str.join to join non-string types (as per PEP 3100)
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.0
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: georg.brandl, gvanrossum, thomaslee
Priority: normal Keywords: patch

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:26adminsetgithub: 45486
2007-09-27 18:13:54gvanrossumsetstatus: open -> closed
resolution: accepted
2007-09-27 18:01:45gvanrossumsetmessages: + msg56177
2007-09-27 16:09:50thomasleesetmessages: + msg56167
2007-09-14 19:33:58gvanrossumsetmessages: + msg55914
2007-09-13 19:58:00georg.brandlsetnosy: + georg.brandl
messages: + msg55898
2007-09-13 09:35:24thomasleesetfiles: + join-autostr-r2.patch
messages: + msg55887
2007-09-13 07:29:43thomasleesetmessages: + msg55882
2007-09-12 19:45:13gvanrossumsetmessages: + msg55870
2007-09-12 19:13:30gvanrossumsetassignee: gvanrossum
messages: + msg55860
nosy: + gvanrossum
2007-09-11 11:44:40loewissetkeywords: + patch
2007-09-11 11:42:58thomasleesetmessages: + msg55821
2007-09-11 11:41:15thomasleecreate