On Sun, 7 Aug 2005 23:52:40 -0400, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> >"Bengt Richter" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> 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. > Have we gone backwards from this? http://groups.google.com/group/comp.lang.python/browse_thread/thread/5fa80186d9f067f4/7a2351b221063a8c I've been meaning to do something with that, to implement @@ decoration, I think probably in the context of a customized importer, where I would be able to control the whole source conversion process, anticipating usage something like (ut is my hodgepodge utility package ;-) from ut.astdecoimport import astdecoimport amodule = astdecoimport('amodule') # searches like import for amodule.py and does its thing Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list