[pypy-commit] pypy list-strategies: When using a string list-strategy have the same behavior on str.join with one element lists.

alex_gaynor noreply at buildbot.pypy.org
Wed Nov 2 19:12:27 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: list-strategies
Changeset: r48673:b387640aa6ba
Date: 2011-11-02 14:12 -0400
http://bitbucket.org/pypy/pypy/changeset/b387640aa6ba/

Log:	When using a string list-strategy have the same behavior on str.join
	with one element lists.

diff --git a/pypy/objspace/std/stringobject.py b/pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py
+++ b/pypy/objspace/std/stringobject.py
@@ -344,6 +344,8 @@
 def str_join__String_ANY(space, w_self, w_list):
     l = space.listview_str(w_list)
     if l is not None:
+        if len(l) == 1:
+            return space.wrap(l[0])
         return space.wrap(w_self._value.join(l))
     list_w = space.listview(w_list)
     size = len(list_w)
diff --git a/pypy/objspace/std/test/test_liststrategies.py b/pypy/objspace/std/test/test_liststrategies.py
--- a/pypy/objspace/std/test/test_liststrategies.py
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -367,12 +367,19 @@
         w_l = self.space.newlist([self.space.wrap('a'), self.space.wrap('b')])
         assert space.listview_str(w_l) == ["a", "b"]
 
-    def test_string_uses_listview_str(self):
+    def test_string_join_uses_listview_str(self):
         space = self.space
         w_l = self.space.newlist([self.space.wrap('a'), self.space.wrap('b')])
         w_l.getitems = None
         assert space.str_w(space.call_method(space.wrap("c"), "join", w_l)) == "acb"
 
+    def test_string_join_returns_same_instance(self):
+        space = self.space
+        w_text = space.wrap("text")
+        w_l = self.space.newlist([w_text])
+        w_l.getitems = None
+        assert space.is_w(space.call_method(space.wrap(" -- "), "join", w_l), w_text)
+
     def test_newlist_str(self):
         space = self.space
         l = ['a', 'b']
diff --git a/pypy/objspace/std/test/test_stringobject.py b/pypy/objspace/std/test/test_stringobject.py
--- a/pypy/objspace/std/test/test_stringobject.py
+++ b/pypy/objspace/std/test/test_stringobject.py
@@ -496,6 +496,7 @@
         assert "-".join(['a', 'b']) == 'a-b'
         text = 'text'
         assert "".join([text]) == text
+        assert " -- ".join([text]) is text
         raises(TypeError, ''.join, 1)
         raises(TypeError, ''.join, [1])
         raises(TypeError, ''.join, [[1]])


More information about the pypy-commit mailing list