[pypy-svn] r79971 - in pypy/trunk/pypy: interpreter/test module/exceptions

arigo at codespeak.net arigo at codespeak.net
Sat Dec 11 12:23:37 CET 2010


Author: arigo
Date: Sat Dec 11 12:23:35 2010
New Revision: 79971

Modified:
   pypy/trunk/pypy/interpreter/test/test_compiler.py
   pypy/trunk/pypy/module/exceptions/interp_exceptions.py
Log:
Fix the test with a custom __repr__ on W_SyntaxError.


Modified: pypy/trunk/pypy/interpreter/test/test_compiler.py
==============================================================================
--- pypy/trunk/pypy/interpreter/test/test_compiler.py	(original)
+++ pypy/trunk/pypy/interpreter/test/test_compiler.py	Sat Dec 11 12:23:35 2010
@@ -938,3 +938,6 @@
             raise Exception("DID NOT RAISE")
         assert str(err1) != str(err2)
         assert repr(err1) != repr(err2)
+        err3 = eval(repr(err1))
+        assert str(err3) == str(err1)
+        assert repr(err3) == repr(err1)

Modified: pypy/trunk/pypy/module/exceptions/interp_exceptions.py
==============================================================================
--- pypy/trunk/pypy/module/exceptions/interp_exceptions.py	(original)
+++ pypy/trunk/pypy/module/exceptions/interp_exceptions.py	Sat Dec 11 12:23:35 2010
@@ -501,12 +501,29 @@
 
     descr_str.unwrap_spec = ['self', ObjSpace]
 
+    def descr_repr(self, space):
+        if (len(self.args_w) == 2
+            and not space.is_w(self.w_lastlineno, space.w_None)
+            and space.int_w(space.len(self.args_w[1])) == 4):
+            # fake a 5-element tuple in the repr, suitable for calling
+            # __init__ again
+            values_w = space.fixedview(self.args_w[1])
+            w_tuple = space.newtuple(values_w + [self.w_lastlineno])
+            args_w = [self.args_w[0], w_tuple]
+            args_repr = space.str_w(space.repr(space.newtuple(args_w)))
+            clsname = self.getclass(space).getname(space, '?')
+            return space.wrap(clsname + args_repr)
+        else:
+            return W_StandardError.descr_repr(self, space)
+    descr_repr.unwrap_spec = ['self', ObjSpace]
+
 W_SyntaxError.typedef = TypeDef(
     'SyntaxError',
     W_StandardError.typedef,
     __new__ = _new(W_SyntaxError),
     __init__ = interp2app(W_SyntaxError.descr_init),
     __str__ = interp2app(W_SyntaxError.descr_str),
+    __repr__ = interp2app(W_SyntaxError.descr_repr),
     __doc__ = W_SyntaxError.__doc__,
     __module__ = 'exceptions',
     msg      = readwrite_attrproperty_w('w_msg', W_SyntaxError),



More information about the Pypy-commit mailing list