[Python-Dev] New and Improved Import Hooks

Just van Rossum just@letterror.com
Fri, 6 Dec 2002 15:55:25 +0100


Guido van Rossum wrote:

> > > I'm not sure if the two-step approach is a big enough deal to
> > > keep it in a new import scheme.
> > 
> > does anyone remember/know why it was done in two steps?
> 
> So you can check whether a module or package exists without importing
> it?

I have no idea how useful that is in practice.

> For the relative import ambiguity?

This is not true at find-module-time: if module x.y does "import z" two things
are tried:

    - Find 'z' on x.__path__
      We know up front that *if* that suceeds that the full name is "x.z",
      so you might as well attempt to *load* "x.y".

    if the above failed:
    
    - Find 'z' on sys.path, in which case the full name is "z".

It doesn't matter much, though, in that as long as we don't want to rewrite
import.c as a whole we're stuck with the two-step scheme anyway.

Just