Fat and happy Pythonistas (was Re: Replacement forkeyword'global' good idea? ...)
Terry Reedy
tjreedy at udel.edu
Sun Aug 7 23:52:40 EDT 2005
"Bengt Richter" <bokr at oz.net> wrote in message
news:42f6b12e.871276739 at news.oz.net...
> I think the relationship of abstract entities and their concrete
> representations
> is very interesting.
ditto
> BTW, maybe this is a place to mention the concept of an AST decorator,
> that works like
> a function decorator except that it is prefixed with @@ instead of @ and
> it operates
> at compile time when the AST becomes available, but before it gets
> translated to code,
> and what gets passed to the decorator is the AST
One can do this much today:
import compiler
new_ast = ast_transformer(compiler.parse('''\
<code here>
''')
However, I can't see any way in the docs to get a code object from the AST.
I believe the AST-to-code compilet is currently being worked on. When it
is, @@ would be nice syntactic sugar but not really necessary.
> The idea is that this form of decoration could transform the
> AST arbitrarily before code generation, and be a very flexible tool
> for mischief of course, but also useful tricky things.
At the moment, we are limited to manipulating concrete text before
compiling it.
Terry J. Reedy
More information about the Python-list
mailing list