Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r88473:ba9187343873
Date: 2016-11-18 17:20 +0100
http://bitbucket.org/pypy/pypy/changeset/ba9187343873/

Log:    Duplicate bytes's 'test_compatibility' for bytearray. Fix the case
        of bytearray.join().

diff --git a/pypy/objspace/std/bytearrayobject.py 
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -150,10 +150,6 @@
     def _join_return_one(self, space, w_obj):
         return False
 
-    def _join_check_item(self, space, w_obj):
-        return not (space.isinstance_w(w_obj, space.w_bytes) or
-                    space.isinstance_w(w_obj, space.w_bytearray))
-
     def ord(self, space):
         if len(self.data) != 1:
             raise oefmt(space.w_TypeError,
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -649,15 +649,6 @@
     def _join_return_one(self, space, w_obj):
         return space.is_w(space.type(w_obj), space.w_str)
 
-    def _join_check_item(self, space, w_obj):
-        try:
-            self._op_val(space, w_obj)
-        except OperationError as e:
-            if not e.match(space, space.w_TypeError):
-                raise
-            return True
-        return False
-
     def descr_lower(self, space):
         return W_BytesObject(self._value.lower())
 
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
@@ -407,13 +407,17 @@
         unwrapped = newlist_hint(size)
         for i in range(size):
             w_s = list_w[i]
-            if self._join_check_item(space, w_s):
+            try:
+                next_string = self._op_val(space, w_s)
+            except OperationError as e:
+                if not e.match(space, space.w_TypeError):
+                    raise
                 raise oefmt(space.w_TypeError,
                             "sequence item %d: expected %s, %T found",
                             i, self._generic_name(), w_s)
             # XXX Maybe the extra copy here is okay? It was basically going to
             #     happen anyway, what with being placed into the builder
-            unwrapped.append(self._op_val(space, w_s))
+            unwrapped.append(next_string)
             prealloc_size += len(unwrapped[i])
 
         sb = self._builder(prealloc_size)
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
@@ -557,3 +557,26 @@
         e = raises(TypeError, bytearray(b'abc').__getitem__, b'd')
         assert str(e.value).startswith(
             'bytearray indices must be integers or slices')
+
+    def test_compatibility(self):
+        # see comments in test_bytesobject.test_compatibility
+        b = bytearray(b'hello world')
+        b2 = b'ello'
+        #not testing result, just lack of TypeError
+        for bb in (b2, bytearray(b2), memoryview(b2)):
+            assert b.split(bb)
+            assert b.rsplit(bb)
+            assert b.split(bb[:1])
+            assert b.rsplit(bb[:1])
+            assert b.join((bb, bb))
+            assert bb in b
+            assert b.find(bb)
+            assert b.rfind(bb)
+            assert b.strip(bb)
+            assert b.rstrip(bb)
+            assert b.lstrip(bb)
+            assert not b.startswith(bb)
+            assert not b.startswith((bb, bb))
+            assert not b.endswith(bb)
+            assert not b.endswith((bb, bb))
+            assert bytearray.maketrans(bb, bb)
diff --git a/pypy/objspace/std/test/test_bytesobject.py 
b/pypy/objspace/std/test/test_bytesobject.py
--- a/pypy/objspace/std/test/test_bytesobject.py
+++ b/pypy/objspace/std/test/test_bytesobject.py
@@ -887,8 +887,7 @@
             assert b.rsplit(bb)
             assert b.split(bb[:1])
             assert b.rsplit(bb[:1])
-            assert b.join((bb, bb)) # cpython accepts bytes and
-                                    # bytearray only, not buffer
+            assert b.join((bb, bb))  # accepts memoryview() since CPython 3.4/5
             assert bb in b
             assert b.find(bb)
             assert b.rfind(bb)
@@ -900,7 +899,6 @@
             assert not b.endswith(bb)
             assert not b.endswith((bb, bb))
             assert bytes.maketrans(bb, bb)
-            assert bytearray.maketrans(bb, bb)
 
     def test_constructor_dont_convert_int(self):
         class A(object):
diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -457,9 +457,6 @@
     def _join_return_one(self, space, w_obj):
         return space.is_w(space.type(w_obj), space.w_unicode)
 
-    def _join_check_item(self, space, w_obj):
-        return not space.isinstance_w(w_obj, space.w_unicode)
-
     def descr_casefold(self, space):
         value = self._val(space)
         builder = self._builder(len(value))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to