473,320 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 1045

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ian Bicking | last post by:
I've been using one of several systems to catch unexpected exceptions and log them (e.g., write to a file, display on web page, email me, etc). But many are built into a particular system, or have...
3
by: Ron Adam | last post by:
I'm trying to understand exception handling better and have a question I haven't been able to find an answer too. Which probably means It won't work, but... Do exceptions that take place get...
1
by: Arthur Chereau | last post by:
Hi, I'm trying to setup viewcvs to work with subversion 1.2.0 on Linux with Python 2.4.1. The last viewcvs (from CVS) needs subversion python bindings. I installed swig and built subversion from...
1
by: gjohannes | last post by:
Hi. I use Idle 1.1.1 on Python 2.4.1. The "Ctrl-" key bindings for indenting do not work on non-us keyboards where brackets are accessed by the "Alt Gr" key. The Tab key seem to work for...
0
by: Nadav | last post by:
Hi, I am writing an AddIn that adds a new EnvDTE.Command, upon setting a key for the command ( Command.Bindings = "Global::f12" ) an exception is being generated... Why can't I set a Key for the...
2
by: tawright915 | last post by:
I created a tabbed app that has over a dozen checkboxes on the second tab. When I add a new record thru dataview, and click on the secodn tab I get and error Object cannot be cast from other...
3
by: Shuaib | last post by:
Hey! I am getting this exception. xml.parsers.expat.ExpatError But I am not able to catch it with "except xml.parsers.expat.ExpatError:" It says "NameError: global name 'xml' is not...
1
by: Jason Yamada-Hanff | last post by:
Hi all, I'm working on a project that would benefit very much from Python Freetype2 bindings (the Fonty Python project). I don't want to duplicate efforts and wrap the library again if we don't...
14
by: Russell E. Owen | last post by:
I have code like this: except Exception, e: self.setState(self.Failed, str(e)) which fails if the exception contains a unicode argument. I did, of course, try unicode(e) but that fails. The...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.