Author: Manuel Jacob
Branch: refactor-str-types
Changeset: r65776:21cef1d9c01c
Date: 2013-07-29 13:43 +0200
http://bitbucket.org/pypy/pypy/changeset/21cef1d9c01c/

Log:    Test and fix to make bytearray.partition() return a new object.

diff --git a/pypy/objspace/std/stringmethods.py 
b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -484,6 +484,9 @@
                                  space.wrap("empty separator"))
         pos = value.find(sub)
         if pos == -1:
+            from pypy.objspace.std.bytearrayobject import W_BytearrayObject
+            if isinstance(self, W_BytearrayObject):
+                self = self._new(value)
             return space.newtuple([self, self._empty(), self._empty()])
         else:
             from pypy.objspace.std.bytearrayobject import W_BytearrayObject
diff --git a/pypy/objspace/std/test/test_bytearrayobject.py 
b/pypy/objspace/std/test/test_bytearrayobject.py
--- a/pypy/objspace/std/test/test_bytearrayobject.py
+++ b/pypy/objspace/std/test/test_bytearrayobject.py
@@ -462,3 +462,7 @@
         for i in range(count):
             b[i:i+1] = 'y'
         assert str(b) == 'y' * count
+
+    def test_partition_return_copy(self):
+        b = bytearray(b'foo')
+        assert b.partition(b'x')[0] is not b
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to