Author: Antonio Cuni <[email protected]>
Branch: py3k
Changeset: r53805:6c0f46ca2071
Date: 2012-03-19 17:22 +0100
http://bitbucket.org/pypy/pypy/changeset/6c0f46ca2071/

Log:    make sure that str(str_subclass('foo')) returns something whose
        exact type is str

diff --git a/pypy/objspace/std/unicodetype.py b/pypy/objspace/std/unicodetype.py
--- a/pypy/objspace/std/unicodetype.py
+++ b/pypy/objspace/std/unicodetype.py
@@ -294,7 +294,12 @@
         typename = space.type(w_res).getname(space)
         msg = "__str__ returned non-string (type %s)" % typename
         raise OperationError(space.w_TypeError, space.wrap(msg))
-    return w_res
+
+    if space.is_w(space.type(w_res), space.w_unicode):
+        return w_res
+    else:
+        # Subtype -- return genuine unicode string with the same value.
+        return space.wrap(space.str_w(w_res))
 
 def descr_new_(space, w_unicodetype, w_object=u'', w_encoding=None, 
w_errors=None):
     # NB. the default value of w_obj is really a *wrapped* empty string:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to