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

Terry Reedy tjreedy at udel.edu
Fri Jul 3 21:33:46 CEST 2015


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.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list