[Patches] [ python-Patches-1098732 ] Enhance tracebacks and stack
traces with vars
SourceForge.net
noreply at sourceforge.net
Thu Feb 10 00:21:04 CET 2005
Patches item #1098732, was opened at 2005-01-09 02:59
Message generated for change (Comment added) made by loewis
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1098732&group_id=5470
Category: Library (Lib)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Skip Montanaro (montanaro)
Assigned to: Nobody/Anonymous (nobody)
Summary: Enhance tracebacks and stack traces with vars
Initial Comment:
I think it would be useful to sometimes have local variable
values printed with tracebacks and stack frames. The
attached patch is a first cut at that. I don't know if
people would want that as the default, so I've defaulted
argument printing to disabled. With arg printing enabled,
executing this script:
#!/usr/bin/env python
import sys
import traceback
def exch(ty, val, tb):
traceback.print_exception(ty, val, tb, args=True)
sys.excepthook = exch
def f(n,d):
return n/d
def g(a):
return a/(a-1)
for i in range(5,-1,-1):
print g(i)
displays this output:
1
1
1
2
Traceback (most recent call last):
File "/Users/skip/tmp/tb.py", line 17, in ?
print g(i)
exch: <function exch at 0x4c46b0>
f: <function f at 0x441330>
g: <function g at 0x441370>
i: 1
File "/Users/skip/tmp/tb.py", line 14, in g
return a/(a-1)
a: 1
ZeroDivisionError: integer division or modulo by zero
----------------------------------------------------------------------
>Comment By: Martin v. Löwis (loewis)
Date: 2005-02-10 00:21
Message:
Logged In: YES
user_id=21627
Philipp Eby commented that he would not like to see this as
a default, as the default already prints too much
information. He also (indirectly) suggested that he would
not like to see it as a command line option, but that he
would prefer to see a different command line option instead
which enters pdb on uncaught exceptions.
----------------------------------------------------------------------
Comment By: Björn Lindqvist (sonderblade)
Date: 2005-02-09 11:44
Message:
Logged In: YES
user_id=51702
I like this idea alot! I usually debug by inserting print
"somevar
=",somevar around where I think the problem code is and this
patch
basically does it automagically for me. I can definitely
image this
patch saving me many hours of debug time. But:
1. It outputs to much information. An unhandled exception
that bubbles
up can be 3-4 stackframes long and seeing all the
variables in
those frames is excessive.
2. I think it would be better if the enhanced traceback was
either
default or activated with a commandline option to Python.
Item 1 maybe can be solved by only outputting those names
that are
contained in the lines in which the exception is raised? So
that the
output in your example becomes:
Traceback (most recent call last):
File "exception.py", line 20, in ?
print g(i)
g: <function g at 0x402efed4>
i: 1
File "exception.py", line 14, in g
return a/(a-1)
a: 1
ZeroDivisionError: integer division or modulo by zero
It feels a little weird to have to hook sys.excepthook. I
think this
idea is to good to be "buried" like that. Hopefully, with some
polishing it can be activated with a commandline option or
become the
default bahaviour.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1098732&group_id=5470
More information about the Patches
mailing list