Painful?: Using the ast module for metaprogramming

Kay Schluehr kay.schluehr at gmx.net
Mon Apr 6 06:40:37 EDT 2009


> -It would be nice if decorators were passed a function's AST instead
> of a function object. As it is I have to use inspect.getsource to
> retrieve the source for the function in question, and then use
> ast.parse, which is a bit inefficient because the cpython parser has
> to already have done this once before.

It doesn't matter that much though because the Python parser is very
efficient and the decorator is applied only once.

The PyGPU project used this approach when I remember it correctly:

http://www.cs.lth.se/home/Calle_Lejdfors/pygpu/




More information about the Python-list mailing list