atsuoishimoto/disptrace — pull request #2 by jonathaneunice (2012-07-17 20:39:46+00:00)
Title: disptrace properly displaying else

I complained that `disptrace` was incorrectly displaying program structure when it comes to `else` clauses. You replied that unfortunately they can't be displayed, because Python's trace function doesn't report execution of the line. Happily, only the second part of your statement was true. ;-)

It's true that Python's trace doesn't land on `else` lines explicitly, but the compiler and language runtime certainly know where they are.

Enclosed you'll find a patch that interrogates the Abstract Syntax Tree (AST) for each traced module to determine where the "missing" `else` statements lie, and to add them back in.

It is certainly extra work to do this, but when a developer is running under trace mode already, performance is already not a huge concern, and a little extra effort is worth it to get a correct trace.

Here's a screenshot of the fixed trace output:

![screencap of fixed feature](http://content.screencast.com/users/jonathaneunice/folders/Jing/media/009c46a6-8467-4860-b5d8-920e6b9de35a/00000129.png)