mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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).
This commit is contained in:
parent
4e02c503e7
commit
f1044293fa
5 changed files with 28 additions and 16 deletions
|
@ -178,6 +178,10 @@ class UnicodeTest(
|
|||
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 @@ class UnicodeTest(
|
|||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue