[pypy-commit] pypy default: OperationError.errorstr() gave results depending on whether the exception

arigo pypy.commits at gmail.com
Tue Jan 24 09:42:02 EST 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r89737:a6f3468a583e
Date: 2017-01-24 15:40 +0100
http://bitbucket.org/pypy/pypy/changeset/a6f3468a583e/

Log:	OperationError.errorstr() gave results depending on whether the
	exception was already normalized or not. Fix

diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -71,6 +71,7 @@
 
     def errorstr(self, space, use_repr=False):
         "The exception class and value, as a string."
+        self.normalize_exception(space)
         w_value = self.get_w_value(space)
         if space is None:
             # this part NOT_RPYTHON
diff --git a/pypy/interpreter/test/test_error.py b/pypy/interpreter/test/test_error.py
--- a/pypy/interpreter/test/test_error.py
+++ b/pypy/interpreter/test/test_error.py
@@ -81,7 +81,18 @@
 def test_errorstr(space):
     operr = OperationError(space.w_ValueError, space.wrap("message"))
     assert operr.errorstr(space) == "ValueError: message"
-    assert operr.errorstr(space, use_repr=True) == "ValueError: 'message'"
+    assert operr.errorstr(space, use_repr=True) == (
+        "ValueError: ValueError('message',)")
+    operr = OperationError(space.w_ValueError, space.w_None)
+    assert operr.errorstr(space) == "ValueError"
+    operr = OperationError(space.w_ValueError,
+        space.newtuple([space.wrap(6), space.wrap(7)]))
+    assert operr.errorstr(space) == "ValueError: (6, 7)"
+    operr = OperationError(space.w_UnicodeDecodeError,
+        space.wrap(('unicodeescape', r'\\x', 0, 2, r'truncated \\xXX escape')))
+    assert operr.errorstr(space) == (
+        "UnicodeDecodeError: 'unicodeescape' codec can't decode "
+        "bytes in position 0-1: truncated \\\\xXX escape")
 
 def test_wrap_oserror():
     class FakeSpace:


More information about the pypy-commit mailing list