[Python-ideas] Enabling access to the AST for Python code

Ben Hoyt benhoyt at gmail.com
Fri May 22 03:57:50 CEST 2015


Not knowing too much about interpreter internals, I guess I was
fishing somewhat for the range of possibilities. :-)

But I was definitely thinking more along the lines of a "co_ast"
attribute on code objects. The new syntax approach might be fun, but
I'd think it's a lot more challenging and problematic to add new
syntax.

-Ben

On Thu, May 21, 2015 at 9:40 PM, Nathaniel Smith <njs at pobox.com> wrote:
> On Thu, May 21, 2015 at 6:18 PM, Ben Hoyt <benhoyt at gmail.com> wrote:
>> Hi Python Ideas folks,
>>
>> (I previously posted a similar message on Python-Dev, but it's a
>> better fit for this list. See that thread here:
>> https://mail.python.org/pipermail/python-dev/2015-May/140063.html)
>>
>> Enabling access to the AST for compiled code would make some cool
>> things possible (C# LINQ-style ORMs, for example), and not knowing too
>> much about this part of Python internals, I'm wondering how possible
>> and practical this would be.
>
> What concretely are you imagining? I can imagine lots of possibilities
> with pretty different properties... e.g., one could have an '.ast'
> attribute attached to every code object, which always tracks the
> source that the code was compiled from. Or one could add a new
> (quasi)quoting syntax, like 'select(! c for c in Customer if
> sum(c.orders.price) > 1000)' where ! is a low-priority operator that
> simply returns the AST of whatever is written to the right of it.
> Or... lots of things, probably.
>
> -n
>
> --
> Nathaniel J. Smith -- http://vorpus.org


More information about the Python-ideas mailing list