Author: Carl Friedrich Bolz <[email protected]>
Branch:
Changeset: r64984:666a4888acee
Date: 2013-06-25 21:34 +0200
http://bitbucket.org/pypy/pypy/changeset/666a4888acee/
Log: merge
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
@@ -25,6 +25,12 @@
w_str = self.space.wrap(u'abcd')
assert self.space.listview_unicode(w_str) == list(u"abcd")
+ def test_new_shortcut(self):
+ space = self.space
+ w_uni = self.space.wrap(u'abcd')
+ w_new = space.call_method(
+ space.w_unicode, "__new__", space.w_unicode, w_uni)
+ assert w_new is w_uni
class AppTestUnicodeStringStdOnly:
def test_compares(self):
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
@@ -296,13 +296,16 @@
encoding, errors = _get_encoding_and_errors(space, w_encoding, w_errors)
# convoluted logic for the case when unicode subclass has a __unicode__
# method, we need to call this method
- if (space.is_w(space.type(w_obj), space.w_unicode) or
+ is_precisely_unicode = space.is_w(space.type(w_obj), space.w_unicode)
+ if (is_precisely_unicode or
(space.isinstance_w(w_obj, space.w_unicode) and
space.findattr(w_obj, space.wrap('__unicode__')) is None)):
if encoding is not None or errors is not None:
raise OperationError(space.w_TypeError,
space.wrap('decoding Unicode is not
supported'))
w_value = w_obj
+ if is_precisely_unicode and space.is_w(w_unicodetype, space.w_unicode):
+ return w_value
else:
if encoding is None and errors is None:
w_value = unicode_from_object(space, w_obj)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit