[pypy-svn] r26928 - in pypy/dist/pypy: annotation tool

arigo at codespeak.net arigo at codespeak.net
Sun May 7 13:33:26 CEST 2006


Author: arigo
Date: Sun May  7 13:33:25 2006
New Revision: 26928

Modified:
   pypy/dist/pypy/annotation/annrpython.py
   pypy/dist/pypy/tool/ansi_print.py
Log:
(pedronis, arigo)
A strange hack to attach extra information to arbitrary exceptions.


Modified: pypy/dist/pypy/annotation/annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/annrpython.py	(original)
+++ pypy/dist/pypy/annotation/annrpython.py	Sun May  7 13:33:25 2006
@@ -1,7 +1,7 @@
 from __future__ import generators
 
 from types import ClassType, FunctionType
-from pypy.tool.ansi_print import ansi_log 
+from pypy.tool.ansi_print import ansi_log, raise_nicer_exception
 from pypy.annotation import model as annmodel
 from pypy.annotation.pairtype import pair
 from pypy.annotation.bookkeeper import Bookkeeper
@@ -656,7 +656,10 @@
         for arg in argcells:
             if isinstance(arg, annmodel.SomeImpossibleValue):
                 raise BlockedInference(self, op)
-        resultcell = consider_meth(*argcells)
+        try:
+            resultcell = consider_meth(*argcells)
+        except Exception:
+            raise_nicer_exception(op)
         if resultcell is None:
             resultcell = annmodel.SomeImpossibleValue()  # no return value
         elif resultcell == annmodel.SomeImpossibleValue():

Modified: pypy/dist/pypy/tool/ansi_print.py
==============================================================================
--- pypy/dist/pypy/tool/ansi_print.py	(original)
+++ pypy/dist/pypy/tool/ansi_print.py	Sun May  7 13:33:25 2006
@@ -64,3 +64,20 @@
                        file=self.file, newline=newline, flush=flush)
  
 ansi_log = AnsiLog()
+
+# ____________________________________________________________
+# Nice helper
+
+def raise_nicer_exception(*extraargs):
+    cls, e, tb = sys.exc_info()
+    str_e = str(e)
+    class ExcSubclass(cls):
+        def __str__(self):
+            lines = [str_e]
+            for extra in extraargs:
+                lines.append('\t.. %r' % (extra,))
+            return '\n'.join(lines)
+    ExcSubclass.__name__ = cls.__name__ + "'"
+    ExcSubclass.__module__ = cls.__module__
+    e.__class__ = ExcSubclass
+    raise ExcSubclass, e, tb



More information about the Pypy-commit mailing list