[pypy-commit] pypy stdlib-3.2.5: fix str() w/ out an object specified & kw only args

pjenvey noreply at buildbot.pypy.org
Fri Apr 4 00:12:04 CEST 2014


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: stdlib-3.2.5
Changeset: r70427:bb6d5f9788c9
Date: 2014-04-03 15:04 -0700
http://bitbucket.org/pypy/pypy/changeset/bb6d5f9788c9/

Log:	fix str() w/ out an object specified & kw only args

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
@@ -341,12 +341,14 @@
         assert str(123) == '123'
         assert str(object=123) == '123'
         assert str([2, 3]) == '[2, 3]'
+        assert str(errors='strict') == ''
         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
+        assert U(errors='strict') == U('')
 
     def test_call_unicode_2(self):
         class X(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
@@ -157,20 +157,18 @@
         return space.newlist_unicode(lst)
 
     @staticmethod
-    @unwrap_spec(w_object=WrappedDefault(u''))
     def descr_new(space, w_unicodetype, w_object=None, w_encoding=None,
                   w_errors=None):
-        # NB. the default value of w_obj is really a *wrapped* empty string:
-        #     there is gateway magic at work
-        w_obj = w_object
-
-        encoding, errors = _get_encoding_and_errors(space, w_encoding,
-                                                    w_errors)
-        if encoding is None and errors is None:
-            w_value = unicode_from_object(space, w_obj)
+        if w_object is None:
+            w_value = W_UnicodeObject.EMPTY
         else:
-            w_value = unicode_from_encoded_object(space, w_obj, encoding,
-                                                  errors)
+            encoding, errors = _get_encoding_and_errors(space, w_encoding,
+                                                        w_errors)
+            if encoding is None and errors is None:
+                w_value = unicode_from_object(space, w_object)
+            else:
+                w_value = unicode_from_encoded_object(space, w_object,
+                                                      encoding, errors)
         if space.is_w(w_unicodetype, space.w_unicode):
             return w_value
 


More information about the pypy-commit mailing list