FPE: Add bindings to exception tracebacks.

N

Nathan

Hi folks!

Throughout my python development career, I've occasionally made
various developer tools to show more information about assertions or
exceptions with less hassle to the programmer. Until now, these tools
didn't pass a utility vs pain-to-use threshold.

Now I've created a tool I believe to have passed that threshold, which
I call "binding annotated exception tracebacks". In short, this tool
adds text showing relevant local bindings to each level in a stack
trace print out.

I consider it to be so useful that it should be part of the standard
library. I'm not sure the best process to propose this (shall I make
a PEP? -is this already an FPE?), so I thought I'd start with a
published early/often patch, then point people to it.

I've submitted a patch against the 2.6 head on the sf tracker as
ticket 1654974, or try this url:

http://sourceforge.net/tracker/index.php?func=detail&aid=1654974&group_id=5470&atid=305470

The patch modifies the traceback module. It's also entirely
reasonable to have this functionality in a new, separate module (and
also it may be implemented in earlier python versions), but for my
personal build I wanted all programs to use this new feature.

Here's an example to clarify. Consider the following script:

#! /usr/bin/env python2.6

import sys
import traceback

# Install annotated exception printing:
sys.excepthook = lambda t, v, b: traceback.print_exception(t, v, b,
annotate=True)

def f(c):
d = 2*c
return g(c)

def g(x):
return (lambda z: z+'foo')(x)

f(42)


-The output (with the patch of course) is:

Traceback (most recent call last):
File "/home/n/tmp/demo-bindann.py", line 16, in <module>
# With bindings:
# f = <function f at 0x300f12f0>
# Source:
f(42)
File "/home/n/tmp/demo-bindann.py", line 11, in f
# With bindings:
c = 42
# g = <function g at 0x300f1330>
# Source:
return g(c)
File "/home/n/tmp/demo-bindann.py", line 14, in g
# With bindings:
x = 42
# Source:
return (lambda z: z+'foo')(x)
File "/home/n/tmp/demo-bindann.py", line 14, in <lambda>
# With bindings:
z = 42
# Source:
return (lambda z: z+'foo')(x)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top