[Python-checkins] r74360 - in python/branches/tk_and_idle_maintenance/Lib/idlelib: PyShell.py run.py

guilherme.polo python-checkins at python.org
Thu Aug 13 05:43:39 CEST 2009


Author: guilherme.polo
Date: Thu Aug 13 05:43:39 2009
New Revision: 74360

Log:
Highlight only the top most exception (experimental).

Modified:
   python/branches/tk_and_idle_maintenance/Lib/idlelib/PyShell.py
   python/branches/tk_and_idle_maintenance/Lib/idlelib/run.py

Modified: python/branches/tk_and_idle_maintenance/Lib/idlelib/PyShell.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/idlelib/PyShell.py	(original)
+++ python/branches/tk_and_idle_maintenance/Lib/idlelib/PyShell.py	Thu Aug 13 05:43:39 2009
@@ -677,7 +677,23 @@
         "Extend base class method to reset output properly"
         self.tkconsole.resetoutput()
         self.checklinecache()
-        InteractiveInterpreter.showtraceback(self)
+
+        type, value, tb = sys.exc_info()
+        sys.last_type = type
+        sys.last_value = value
+        sys.last_traceback = tb
+        tblist = traceback.extract_tb(tb)
+        del tblist[:1]
+        sys.stderr.write('\nTraceback (most recent call last):\n')
+        traceback
+        # Highlight only topmost exception
+        first, rest = [tblist[0]], tblist[1:]
+        traceback.print_list(first, file=sys.stderr)
+        if rest:
+            traceback.print_list(rest, file=sys.stdout)
+        lines = traceback.format_exception_only(typ, val)
+        map(sys.stderr.write, lines)
+
         if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"):
             self.tkconsole.open_stack_viewer()
 

Modified: python/branches/tk_and_idle_maintenance/Lib/idlelib/run.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/idlelib/run.py	(original)
+++ python/branches/tk_and_idle_maintenance/Lib/idlelib/run.py	Thu Aug 13 05:43:39 2009
@@ -158,7 +158,11 @@
     exclude = ("run.py", "rpc.py", "threading.py", "Queue.py",
                "RemoteDebugger.py", "bdb.py")
     cleanup_traceback(tbe, exclude)
-    traceback.print_list(tbe, file=efile)
+    # Highlight only topmost exception
+    first, rest = [tbe[0]], tbe[1:]
+    traceback.print_list(first, file=efile)
+    if rest:
+        traceback.print_list(rest, file=sys.stdout)
     lines = traceback.format_exception_only(typ, val)
     for line in lines:
         print>>efile, line,


More information about the Python-checkins mailing list