[Python-ideas] Verbose traceback formatting
Masklinn
masklinn at masklinn.net
Wed Aug 29 07:15:26 CEST 2012
On 2012-08-29, at 00:26 , Mike Graham wrote:
> It's possible to give a lot more on error than the default traceback
> gives you. I propose that Python should ship a more verbose formatter
It already does: http://docs.python.org/py3k/library/cgitb.html
> cat > test.py
import cgitb
cgitb.enable(format='text')
def a():
b()
def b():
c()
def c():
assert False, "blow up"
a()
^C
> python3 test.py
AssertionError
Python 3.2.3: python
Wed Aug 29 07:08:14 2012
A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred.
test.py in <module>()
7 c()
8 def c():
9 assert False, "blow up"
10
11 a()
a = <function a>
test.py in a()
3
4 def a():
5 b()
6 def b():
7 c()
global b = <function b>
test.py in b()
5 b()
6 def b():
7 c()
8 def c():
9 assert False, "blow up"
global c = <function c>
test.py in c()
7 c()
8 def c():
9 assert False, "blow up"
10
11 a()
AssertionError: blow up
__cause__ = None
__class__ = <class 'AssertionError'>
__context__ = None
__delattr__ = <method-wrapper '__delattr__' of AssertionError object>
__dict__ = {}
__doc__ = 'Assertion failed.'
__eq__ = <method-wrapper '__eq__' of AssertionError object>
__format__ = <built-in method __format__ of AssertionError object>
__ge__ = <method-wrapper '__ge__' of AssertionError object>
__getattribute__ = <method-wrapper '__getattribute__' of AssertionError object>
__gt__ = <method-wrapper '__gt__' of AssertionError object>
__hash__ = <method-wrapper '__hash__' of AssertionError object>
__init__ = <method-wrapper '__init__' of AssertionError object>
__le__ = <method-wrapper '__le__' of AssertionError object>
__lt__ = <method-wrapper '__lt__' of AssertionError object>
__ne__ = <method-wrapper '__ne__' of AssertionError object>
__new__ = <built-in method __new__ of type object>
__reduce__ = <built-in method __reduce__ of AssertionError object>
__reduce_ex__ = <built-in method __reduce_ex__ of AssertionError object>
__repr__ = <method-wrapper '__repr__' of AssertionError object>
__setattr__ = <method-wrapper '__setattr__' of AssertionError object>
__setstate__ = <built-in method __setstate__ of AssertionError object>
__sizeof__ = <built-in method __sizeof__ of AssertionError object>
__str__ = <method-wrapper '__str__' of AssertionError object>
__subclasshook__ = <built-in method __subclasshook__ of type object>
__traceback__ = <traceback object>
args = ('blow up',)
with_traceback = <built-in method with_traceback of AssertionError object>
The above is a description of an error in a Python program. Here is
the original traceback:
Traceback (most recent call last):
File "test.py", line 11, in <module>
a()
File "test.py", line 5, in a
b()
File "test.py", line 7, in b
c()
File "test.py", line 9, in c
assert False, "blow up"
AssertionError: blow up
> and a command line switch to use it.
Adding the hook on `python -mcgitb script`? In the style of -mpdb?
More information about the Python-ideas
mailing list