[pypy-commit] pypy py3k: revert 6c0f46ca2071 and 0c0fd7170ad3, and move the logic inside str.__str__, also improving test_call_unicode. Now bot test_call_unicode and test_returns_subclass work
antocuni
noreply at buildbot.pypy.org
Tue Mar 20 15:52:33 CET 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r53830:5f4d5bfbc2d3
Date: 2012-03-20 11:03 +0100
http://bitbucket.org/pypy/pypy/changeset/5f4d5bfbc2d3/
Log: revert 6c0f46ca2071 and 0c0fd7170ad3, and move the logic inside
str.__str__, also improving test_call_unicode. Now bot
test_call_unicode and test_returns_subclass work
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
@@ -297,6 +297,7 @@
class U(str):
pass
assert str(U()).__class__ is str
+ assert U().__str__().__class__ is str
assert U('test') == 'test'
assert U('test').__class__ is U
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
@@ -94,7 +94,11 @@
return ''.join(result)
def str__Unicode(space, w_uni):
- return w_uni
+ if space.is_w(space.type(w_uni), space.w_unicode):
+ return w_uni
+ else:
+ # Subtype -- return genuine unicode string with the same value.
+ return space.wrap(space.unicode_w(w_uni))
def eq__Unicode_Unicode(space, w_left, w_right):
return space.newbool(w_left._value == w_right._value)
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,12 +294,7 @@
typename = space.type(w_res).getname(space)
msg = "__str__ returned non-string (type %s)" % typename
raise OperationError(space.w_TypeError, space.wrap(msg))
-
- 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.unicode_w(w_res))
+ return 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:
More information about the pypy-commit
mailing list