[Python-Dev] New and Improved Import Hooks

Gordon McMillan gmcm@hypernet.com
Wed, 4 Dec 2002 12:07:32 -0500


On 4 Dec 2002 at 16:28, Moore, Paul wrote:

> BTW, on Gordon's site, in the iu documentation, he
> mentions that "the assumption that sys.path is
> occupied solely by strings seems ineradicable". I
> don't know if he's got any specific issues in mind,
> but it might be worth checking out (get the screams
> of protest out of the way before the code goes in
> :-)) 
> 
> I've copied Gordon in case he can give any
> specifics... 

Code like this:
 for p in sys.path:
   x = os.path.join(p, ...)
   ....
is very common (I patched linecache.py for this
after imputil went into the std lib). Since PYTHONPATH
can consist only of strings, it seems wise to 
tackle the issue (dealing with strings that describe
non-directory collections of modules) instead of postponing it. Also seems sensible to make it
so that if X works on PYTHONPATH, 
sys.path.append(X) should work, too.

The shadowpath consists only of objects, and
len(shadowpath) <= len(sys.path); it's either
lazy or caching, depending on POV.

[There's a metapath, too. That lets you put
overrides in front. You can even override
frozen and builtin modules.]

-- Gordon
http://www.mcmillan-inc.com/