[pypy-commit] pypy py3.3: Fix error message for converting surrogate to int

Ian Foote noreply at buildbot.pypy.org
Sun Jul 27 14:12:36 CEST 2014


Author: Ian Foote <python at ian.feete.org>
Branch: py3.3
Changeset: r72568:13703de458c9
Date: 2014-07-27 14:01 +0200
http://bitbucket.org/pypy/pypy/changeset/13703de458c9/

Log:	Fix error message for converting surrogate to int

diff --git a/pypy/objspace/std/test/test_intobject.py b/pypy/objspace/std/test/test_intobject.py
--- a/pypy/objspace/std/test/test_intobject.py
+++ b/pypy/objspace/std/test/test_intobject.py
@@ -418,11 +418,11 @@
                 return None
         inst = a()
         raises(TypeError, int, inst)
-        assert inst.ar == True 
+        assert inst.ar == True
 
         class b(object):
-            pass 
-        raises((AttributeError,TypeError), int, b()) 
+            pass
+        raises((AttributeError,TypeError), int, b())
 
     def test_special_long(self):
         class a(object):
@@ -504,6 +504,11 @@
             else:
                 assert False, value
 
+    def test_int_error_msg_surrogate(self):
+        value = u'123\ud800'
+        e = raises(ValueError, int, value)
+        assert str(e.value) == "invalid literal for int() with base 10: %r" % value
+
     def test_fake_int_as_base(self):
         class MyInt(object):
             def __init__(self, x):
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
@@ -1166,7 +1166,7 @@
             except KeyError:
                 pass
         result[i] = unichr(uchr)
-    return unicodehelper.encode_utf8(space, u''.join(result))
+    return unicodehelper.encode_utf8(space, u''.join(result), allow_surrogates=True)
 
 
 _repr_function, _ = make_unicode_escape_function(


More information about the pypy-commit mailing list