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).
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 64cca3f..1358419 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -178,6 +178,10 @@
def test_join(self):
string_tests.MixinStrUnicodeUserStringTest.test_join(self)
+ class MyWrapper:
+ def __init__(self, sval): self.sval = sval
+ def __str__(self): return self.sval
+
# mixed arguments
self.checkequalnofix('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
self.checkequalnofix('abcd', '', 'join', ('a', 'b', 'c', 'd'))
@@ -186,6 +190,8 @@
self.checkequalnofix('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
self.checkequalnofix('abcd', '', 'join', ('a', 'b', 'c', 'd'))
self.checkequalnofix('w x y z', ' ', 'join', string_tests.Sequence('wxyz'))
+ self.checkequalnofix('1 2 foo', ' ', 'join', [1, 2, MyWrapper('foo')])
+ self.checkraises(TypeError, ' ', 'join', [1, 2, 3, bytes()])
def test_replace(self):
string_tests.CommonTest.test_replace(self)