[Python-Dev] New universal import mechanism ( Re: [Python-checkins] python/dist/src/Python import.c,2.210,2.211)

Just van Rossum just@letterror.com
Mon, 2 Dec 2002 20:19:22 +0100


Greg Ward wrote:

> >     - a hook either returns None ("module not found") or a two-tuple:
> >       (loadfunc, cookie). loadfunc is a callable object that will
> 
> Sounds sensible, but please s/cookie/data/ (or similar).

Ok.

> >       be called with two arguments: the fullname and "cookie". The
> >       cookie is just an arbitrary object, private to the hook. The
> >       loaderfunc must return the imported module.
> >     - (Currently it expects that the loaderfunc will insert the module
> >       in sys.path, I'm not sure I like that. Actually, I am sure I
>                ^^^^
> 
> You really meant sys.module, right? 

sys.modules actually ;-)

> >       don't like that <wink>, but changing that would require more
> >       changes to import.c that I'd like. I'll have to investigate.)
> 
> I agree: if an import hook is not responsible for checking sys.modules
> before doing an import, it should not be responsible for updating
> sys.modules after an import.

I hadn't even looked at it that way, but yeah, that's an excellent rationale...
But: they _may_ do so if they desire; a module is even allowed to stuff a whole
different object into sys.modules instead of itself, so I'll have to be careful.

Just