[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pypy-svn
Subject:    [pypy-commit] pypy default: unicode(encoding='x') returns the empty string u''.
From:       amauryfa <pypy.commits () gmail ! com>
Date:       2018-12-30 2:22:08
Message-ID: 5c282bd0.1c69fb81.d8910.0092 () mx ! google ! com
[Download RAW message or body]

Author: Amaury Forgeot d'Arc <amauryfa@gmail.com>
Branch: 
Changeset: r95534:24f6622d7e24
Date: 2018-12-29 23:06 +0100
http://bitbucket.org/pypy/pypy/changeset/24f6622d7e24/

Log:	unicode(encoding='x') returns the empty string u''. This behavior is
	explicitly tested in py3.5.

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
@@ -1163,9 +1163,8 @@
         assert type(unicode(z)) is unicode
         assert unicode(z) == u'foobaz'
         #
-        # two completely corner cases where we differ from CPython:
-        #assert unicode(encoding='supposedly_the_encoding') == u''
-        #assert unicode(errors='supposedly_the_error') == u''
+        assert unicode(encoding='supposedly_the_encoding') == u''
+        assert unicode(errors='supposedly_the_error') == u''
         e = raises(TypeError, unicode, u'', 'supposedly_the_encoding')
         assert str(e.value) == 'decoding Unicode is not supported'
         e = raises(TypeError, unicode, u'', errors='supposedly_the_error')
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
@@ -192,23 +192,20 @@
         return space.newlist_unicode(lst)
 
     @staticmethod
-    @unwrap_spec(w_string=WrappedDefault(""))
-    def descr_new(space, w_unicodetype, w_string, w_encoding=None,
+    def descr_new(space, w_unicodetype, w_string=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_string
-
         encoding, errors = _get_encoding_and_errors(space, w_encoding,
                                                     w_errors)
-        if encoding is None and errors is None:
-            # this is very quick if w_obj is already a w_unicode
-            w_value = unicode_from_object(space, w_obj)
+        if w_string is None:
+            w_value = W_UnicodeObject.EMPTY
+        elif encoding is None and errors is None:
+            # this is very quick if w_string is already a w_unicode
+            w_value = unicode_from_object(space, w_string)
         else:
-            if space.isinstance_w(w_obj, space.w_unicode):
+            if space.isinstance_w(w_string, space.w_unicode):
                 raise oefmt(space.w_TypeError,
                             "decoding Unicode is not supported")
-            w_value = unicode_from_encoded_object(space, w_obj,
+            w_value = unicode_from_encoded_object(space, w_string,
                                                   encoding, errors)
         if space.is_w(w_unicodetype, space.w_unicode):
             return w_value
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic