1. Van Lindberg
  2. pypy

Commits

Alex Gaynor  committed b387640

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

  • Participants
  • Parent commits 1159092
  • Branches list-strategies

Comments (0)

Files changed (3)

File pypy/objspace/std/stringobject.py

View file
 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)

File pypy/objspace/std/test/test_liststrategies.py

View file
         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']

File pypy/objspace/std/test/test_stringobject.py

View file
         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]])