Looking to do AST inspection/transform on all imports.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Looking to do AST inspection/transform on all imports.

Jonathan Feinberg-2
It's easy enough to arbitrarily transform the AST of, say, a user script before exec()ing it, but I'd like to intercept Python code as it's imported and transform it before it's executed. I know, vaguely, about the existence of "import hooks", but thought I'd ask here whether that's the right tree to bark up before investing any serious time in the effort.

Just to be clear, my idea is that the user writes

from foo import Foo

in their script, and I am given the text of foo.py to do what I wish to (which would be to compile it, and transform the AST). Am I in the ballpark?

--
Jonathan Feinberg  [hidden email]  http://MrFeinberg.com/

------------------------------------------------------------------------------
Time is money. Stop wasting it! Get your web API in 5 minutes.
www.restlet.com/download
http://p.sf.net/sfu/restlet
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users