[Patches] [ python-Patches-1654974 ] sys.excepthook shows relevant bindings.

SourceForge.net noreply at sourceforge.net
Thu Feb 8 10:50:36 CET 2007

Patches item #1654974, was opened at 2007-02-08 09:46
Message generated for change (Comment added) made by nejucomo
You can respond by visiting: 

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nefarious CodeMonkey, Jr. (nejucomo)
Assigned to: Nobody/Anonymous (nobody)
Summary: sys.excepthook shows relevant bindings.

Initial Comment:
The attached module provides a suitable replacement for sys.excepthook to handle uncaught exceptions.

The output is the same, except after each source line shown, a list of relevant bindings is shown.

Here's a quick example from the tail end of a test:

  File "./test-exprann.py", line 16, in f
    assert c == 12
    # With bindings:
    # c = 42

The bindings shown are the intersection of the code object "co_names" and the non-keyword name tokens in the parsed source line.  The goal is to only show bindings relevant to the exception.

I hope the utility of this is self-evident to any programmer.  I tried testing it with crazy expressions containing nonfree bindings (such as lambda's and list comprehensions), so I think it behaves well in most circumstances.

The performance might be bad (it parses each line in the backtrace), but I figure it is worth it for uncaught exceptions.

Let me know if you find this tool useful.



>Comment By: Nefarious CodeMonkey, Jr. (nejucomo)
Date: 2007-02-08 09:50

Logged In: YES 
Originator: YES

BTW, I only tested this on python 2.4.

Because it examines the parse tree (very simply), it may not work if the
AST format changes.  The only parsing it does is search for all NAME tokens
which are not keywords, so I assumed this was stable across releases.


You can respond by visiting: 

More information about the Patches mailing list