ipython/ipython — pull request #2301 by takluyver (2012-08-14 12:52:14+00:00)
Title: Ast transfomers

Not ready for merge yet.

This is the next step towards IPEP 2 (#2293). It provides a mechanism that third parties can register an instance of a subclass of `ast.NodeTransformer` - or anything that quacks the same way, although the docstring doesn't currently mention that. It will be applied to the REPL input before executing it.

For now, transformers are expected to catch their own errors. If an error leaks out of a transformer, it is disabled, and a warning printed. We could relax this restriction in future.

In normal use, with no transformers defined, it should have negligible impact on performance, as we were already using the AST, so there's just one extra no-op function call.

I still need to figure out which IPython special features need to be aware of this, like `%timeit`, `%time`, macros - and how to integrate that. I had a brief look at `%time` and `%timeit` - it should be simple enough for the former, but trickier for the latter, because of the use of the codestring template `timeit.template`.