[Python-ideas] AST Hash

Andrew Barnert abarnert at yahoo.com
Thu Sep 12 07:15:15 CEST 2013


From: Andrew Barnert <abarnert at yahoo.com>

Sent: Wednesday, September 11, 2013 10:12 PM


> But there's an obvious answer here that takes care of all of this: Just has 
> the compiled code objects.

… 

> There are some obvious downsides to this, but I don't think any of them are 
> too serious.

…

> But I'm sure someone will come up with something big and obvious that 
> I'm missing.


Actually, I just thought of one.

Let's say mod.py looks like this:

    def f():
        def g():
            pass

How do we get the code for the g function?

With an AST, it's obvious—you may not get sufficient/correct context, but at least you can get to it.

With a compiled module, whether we explicitly compile mod.py or import it or whatever… well, there's a code object for g compiled in there, and it even knows that it's part of module fc, and from line 1 of fc.py, and so on… but you can't access it as fc.g, or anything else obvious, without picking through the compiled code format.



More information about the Python-ideas mailing list