<!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>
&gt; On 4/8/06, Phillip J. Eby &lt;pje@telecommunity.com&gt; wrote:<BR>
&gt; &gt; To me an AST access feature would only be useful for<BR>
&gt; &gt; changing the &quot;VM&quot; that Python code runs on.&nbsp; For example,<BR>
&gt; &gt; there is an object-relational mapper out there (I think<BR>
&gt; &gt; it's Robert Brewer's DejaVu system) that takes Python<BR>
&gt; &gt; generator expressions and converts them into SQL.&nbsp; Right<BR>
&gt; &gt; now it does it by bytecode hacking, because the only<BR>
&gt; &gt; alternative is to parse a string.<BR>
&gt;<BR>
&gt; I can see how reading the AST could be useful here,<BR>
&gt; but Python 2.5 already has that:<BR>
&gt;<BR>
&gt; &gt;&gt;&gt; expr = compile('(x**y for x, y in z)', '&lt;string&gt;', '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>
&gt; Do the use-cases here really need to change the AST on<BR>
&gt; the original function?&nbsp; What's wrong with creating a<BR>
&gt; 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>