summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-08-23 23:23:54 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-08-23 23:23:54 (GMT)
commit674f241e9c5bd0f40418580d74e3c8e430f651cc (patch)
treede1ddc670e5b000922d74d31834e45039e823746 /Lib
parentdd50cb748a4dc317891a8df50adc8371db7598cc (diff)
downloadcpython-674f241e9c5bd0f40418580d74e3c8e430f651cc.zip
cpython-674f241e9c5bd0f40418580d74e3c8e430f651cc.tar.gz
cpython-674f241e9c5bd0f40418580d74e3c8e430f651cc.tar.bz2
SF Patch #1007087: Return new string for single subclass joins (Bug #1001011)
(Patch contributed by Nick Coghlan.) Now joining string subtypes will always return a string. Formerly, if there were only one item, it was returned unchanged.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_string.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py
index 859dd4e..ba9d9d3 100644
--- a/Lib/test/test_string.py
+++ b/Lib/test/test_string.py
@@ -52,6 +52,29 @@ class StringTest(
self.checkraises(TypeError, string_tests.BadSeq1(), 'join', ' ')
self.checkequal('a b c', string_tests.BadSeq2(), 'join', ' ')
+ def test_bug1001011(self):
+ # Make sure join returns a NEW object for single item sequences
+ # involving a subclass
+ # Make sure that it is of the appropriate type
+ # Check the optimisation still occurs for standard objects
+ class str_subclass(str): pass
+ s1 = str_subclass('abcd')
+ s2 = ''.join([s1])
+ self.failIf(s1 is s2)
+ self.assertEqual(type(s2), type(''))
+ s3 = 'abcd'
+ s4 = ''.join([s3])
+ self.failUnless(s3 is s4)
+ if test_support.have_unicode:
+ class unicode_subclass(unicode): pass
+ u1 = unicode_subclass(u'abcd')
+ u2 = ''.join([u1])
+ self.failIf(u1 is u2)
+ self.assertEqual(type(u2), type(u''))
+ u3 = u'abcd'
+ u4 = ''.join([u3])
+ self.failUnless(u3 is u4)
+
class ModuleTest(unittest.TestCase):
def test_attrs(self):