[Python-Dev] New and Improved Import Hooks

Just van Rossum just@letterror.com
Sat, 7 Dec 2002 00:55:13 +0100


Guido van Rossum wrote:

> The problem with trying to load x.y right away is that then you can't
> distinguish between "x.y doesn't exist" (and then you go to step 2)
> as opposed to "x.y exists, but it tries to import something else that
> raised ImportError" (and then you should simply propagate the
> exception).

Also not true: a function that finds *and* loads a module can return None for
"module not found", a new module object upon succes, and propagate an error if
one did occur during import. I'm tempted to make my new import hook scheme work
that way: it avoids a few hoops I have to go through with import.c, as right now
I'm quite limited what zipimporter.find_module() can communicate to
zipimporter.load_module(). (It would also make it even closer to iu.py ;-)

Just