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

Neil Girdhar mistersheik at gmail.com
Fri Jul 3 22:44:36 CEST 2015

On Fri, Jul 3, 2015 at 3:33 PM, Terry Reedy <tjreedy at udel.edu> wrote:

> As I remember, the proposal is or would have to be to give code objects a
> new attribute -- co_ast.  This would require an addition to marshal to
> compress and uncompress asts.  It would expand both on-disk .pyc files and
> even more, in-memory code objects.
> On 7/2/2015 4:25 PM, Neil Girdhar wrote:
>> Why would it require "a lot of extra memory"?
> > A program text size is measured in megabytes,
> > and the AST is typically more compact than the code as text.
> Why do you think that?  Each text token becomes an node object that is a
> minimun 56 bytes (on my 64-bit Win7 3.5). For instance, a one-byte '+' (in
> all-ascii code) balloons to at least 56 bytes in the ast and compiled back
> down to 1 byte in the byte code.  I expect the uncompressed in-memory size
> of asts to be several times the current size of corresponding code objects.

Yes, but in fairness whitespace disappears, and there are some
optimizations to the AST that could be made so that nodes with a single
child for example are elided.

> --
> Terry Jan Reedy
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
> --
> --- You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/python-ideas/F4KEYEd6Cs0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150703/7f725b95/attachment.html>

More information about the Python-ideas mailing list