[pypy-commit] pypy py3k: unicode string should not join bytes items

amauryfa noreply at buildbot.pypy.org
Sun Nov 6 20:59:20 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r48843:4dbce2bccfb1
Date: 2011-10-26 17:08 +0200
http://bitbucket.org/pypy/pypy/changeset/4dbce2bccfb1/

Log:	unicode string should not join bytes items

diff --git a/pypy/objspace/std/test/test_unicodeobject.py b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -28,6 +28,7 @@
             assert a == b
             assert type(a) == type(b)
         check(', '.join(['a']), 'a')
+        raises(TypeError, ','.join, [b'a']) 
 
     def test_contains(self):
         assert '' in 'abc'
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
@@ -124,17 +124,12 @@
         if self and i != 0:
             sb.append(self)
         w_s = list_w[i]
-        if isinstance(w_s, W_UnicodeObject):
-            # shortcut for performance
-            sb.append(w_s._value)
-        else:
-            try:
-                sb.append(space.unicode_w(w_s))
-            except OperationError, e:
-                if not e.match(space, space.w_TypeError):
-                    raise
-                raise operationerrfmt(space.w_TypeError,
-                    "sequence item %d: expected string or Unicode", i)
+        if not isinstance(w_s, W_UnicodeObject):
+            raise operationerrfmt(
+                space.w_TypeError,
+                "sequence item %d: expected string, %s "
+                "found", i, space.type(w_s).getname(space))
+        sb.append(w_s._value)
     return space.wrap(sb.build())
 
 def hash__Unicode(space, w_uni):


More information about the pypy-commit mailing list