Showing the method's class in expection's traceback

Duncan Booth duncan.booth at invalid.invalid
Thu May 22 06:55:44 EDT 2008


Bruno Desthuilliers <bruno.42.desthuilliers at websiteburo.invalid> wrote:

> Not to say that your concerns are pointless, and that things cannot be 
> improved somehow, but this is not that trivial, and there may be 
> ambuiguities in some not so rare cases.

It might be worth considering an alternative approach here: a formatted 
exception includes the relevant source lines (where possible).

The source lines are cached by the module linecache.py and it probably 
wouldn't be too hard to build on the line cache so that it also scans the 
source lines looking for class statements and recording the start and end 
line numbers for each class.

That way any classname displayed would be based on the actual source 
nesting and even static methods or functions injected from another class 
would work 'correctly' (at some level).

-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list