Commits

Philip Jenvey committed bb6d5f9

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

  • Participants
  • Parent commits 81af532
  • Branches stdlib-3.2.5

Comments (0)

Files changed (2)

File pypy/objspace/std/test/test_unicodeobject.py

         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):

File pypy/objspace/std/unicodeobject.py

         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