Painful?: Using the ast module for metaprogramming

Kay Schluehr kay.schluehr at
Mon Apr 6 12:40:37 CEST 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:

More information about the Python-list mailing list