[pypy-commit] pypy py3k: bah; rpython+unicode is hard

antocuni noreply at buildbot.pypy.org
Wed Jul 18 22:43:56 CEST 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r56201:6169d4adf0f6
Date: 2012-07-18 22:43 +0200
http://bitbucket.org/pypy/pypy/changeset/6169d4adf0f6/

Log:	bah; rpython+unicode is hard

diff --git a/pypy/objspace/std/strutil.py b/pypy/objspace/std/strutil.py
--- a/pypy/objspace/std/strutil.py
+++ b/pypy/objspace/std/strutil.py
@@ -184,8 +184,12 @@
     try:
         ascii_s = s.encode('ascii')
     except UnicodeEncodeError:
-        # if it's not ASCII, it certainly is not one of the cases below
-        pass
+        # if s is not ASCII, it certainly is not a float literal (because the
+        # unicode-decimal to ascii-decimal conversion already happened
+        # earlier). We just set ascii_s to something which will fail when
+        # passed to rstring_to_float, to keep the code as similar as possible
+        # to the one we have on default
+        ascii_s = "not a float"
     else:
         low = ascii_s.lower()
         if low == "-inf" or low == "-infinity":
@@ -199,10 +203,9 @@
         elif low == "-nan":
             return -NAN
 
-    # rstring_to_float only supports byte strings, but we have an unicode
-    # here. Do as CPython does: convert it to UTF-8
-    mystring = s.encode('utf-8')
     try:
-        return rstring_to_float(mystring)
+        return rstring_to_float(ascii_s)
     except ValueError:
+        # note that we still put the original unicode string in the error
+        # message, not ascii_s
         raise ParseStringError(u"invalid literal for float(): '%s'" % s)


More information about the pypy-commit mailing list