470,811 Members | 1,170 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,811 developers. It's quick & easy.

FPE: Add bindings to exception tracebacks.

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...70&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'
Feb 19 '07 #1
0 954

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ian Bicking | last post: by
3 posts views Thread by Ron Adam | last post: by
1 post views Thread by Arthur Chereau | last post: by
2 posts views Thread by tawright915 | last post: by
3 posts views Thread by Shuaib | last post: by
1 post views Thread by Jason Yamada-Hanff | last post: by
14 posts views Thread by Russell E. Owen | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.