[Python-Dev] a Python interface for the AST (WAS: DRAFT: python-dev...)

Phillip J. Eby pje at telecommunity.com
Wed Nov 23 03:58:58 CET 2005


At 06:32 PM 11/22/2005 -0800, Brett Cannon wrote:
> >  Hmm, it would be nice to give a function a module
> > name (like from an import statement) and have Python resolve it using
> > the normal sys.path iteration.
> >
>
>Yep, import path -> filename path would be cool.

Zipped and frozen modules don't have filename paths, so I'd personally 
rather see fewer stdlib modules making the assumption that modules are 
files.  Instead, extensions to the PEP 302 loader protocol should be used 
to support introspection, assuming there aren't already equivalent 
capabilities available.  For example, PEP 302 allows a 'get_source()' 
method on loaders, and I believe the zipimport loader supports that.  (I 
don't know about frozen modules.)

The main barrier to this being really usable is the absence of loader 
objects for the built-in import process.  This was proposed by PEP 302, but 
never actually implemented, probably due to time constraints on the Python 
2.3 release schedule.

It's relatively easy to implement this "missing loader class" in Python, 
though, and in fact the PEP 302 regression test in the stdlib does exactly 
that.  Some work, however, would be required to port this to C and expose 
it from an appropriate module (imp?).



More information about the Python-Dev mailing list