[Python-3000] AST access (WAS: Adaptation vs. Generic Functions)

Robert Brewer fumanchu at amor.org
Sun Apr 9 22:38:19 CEST 2006


Steven Bethard wrote:
> On 4/8/06, Phillip J. Eby <pje at telecommunity.com> wrote:
> > To me an AST access feature would only be useful for
> > changing the "VM" that Python code runs on.  For example,
> > there is an object-relational mapper out there (I think
> > it's Robert Brewer's DejaVu system) that takes Python
> > generator expressions and converts them into SQL.  Right
> > now it does it by bytecode hacking, because the only
> > alternative is to parse a string.
> 
> I can see how reading the AST could be useful here,
> but Python 2.5 already has that:
> 
> >>> expr = compile('(x**y for x, y in z)', '<string>', 'eval', 0x400)

Part of the benefit of the bytecode-hacking is that your expression never has to be in a string. This is a win for readability, and also means you can use the usual helpers like syntax coloring, pychecker, etc. It also means you can early-bind a lot of constants from the scope where the expression is declared without resorting to string-interpolation; that cuts down on SQL-injection attacks in my case.

> Do the use-cases here really need to change the AST on
> the original function?  What's wrong with creating a
> new function?

Mine don't need to modify the original AST; I'd be happy making a new function. That's what I do now (just at the bytecode level, joining two functions into one with the appropriate JUMP code).


Robert Brewer
System Architect
Amor Ministries
fumanchu at amor.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20060409/b3dee374/attachment.html 


More information about the Python-3000 mailing list