<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>RE: [Python-3000] AST access (WAS: Adaptation vs. Generic Functions)</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Steven Bethard wrote:<BR>
> On 4/8/06, Phillip J. Eby <pje@telecommunity.com> wrote:<BR>
> > To me an AST access feature would only be useful for<BR>
> > changing the "VM" that Python code runs on. For example,<BR>
> > there is an object-relational mapper out there (I think<BR>
> > it's Robert Brewer's DejaVu system) that takes Python<BR>
> > generator expressions and converts them into SQL. Right<BR>
> > now it does it by bytecode hacking, because the only<BR>
> > alternative is to parse a string.<BR>
><BR>
> I can see how reading the AST could be useful here,<BR>
> but Python 2.5 already has that:<BR>
><BR>
> >>> expr = compile('(x**y for x, y in z)', '<string>', 'eval', 0x400)<BR>
<BR>
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.<BR>
<BR>
> Do the use-cases here really need to change the AST on<BR>
> the original function? What's wrong with creating a<BR>
> new function?<BR>
<BR>
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).<BR>
<BR>
<BR>
Robert Brewer<BR>
System Architect<BR>
Amor Ministries<BR>
fumanchu@amor.org</FONT>
</P>
</BODY>
</HTML>