[Python-Dev] Another approach for the import mechanism

Martin v. Löwis martin@v.loewis.de
06 Dec 2002 07:34:16 +0100


Gustavo Niemeyer <niemeyer@conectiva.com> writes:

> > It appears that this can't be really done with the proposed mechanism,
> > as you want to have a multiple hooks for a single source "URL".
> 
> As you have mentioned below, all hooks registered are called, if
> the previous ones failed. So there shouldn't be any problem.

I mentioned this as a theoretical architecture which is not going to
be implemented by Just. Whether or not this is a problem, I don't
know.

> > So you are back to calling all registered hooks for all items on
> > sys.path, which might be expensive.
> 
> Agreed. But further hooks are only called if the default one failed.

Again, this is *not* the strategy that Just proposes, and, unless
somebody provides an implementation of it, not one that will matter.

As for "only called if the default one failed": This will be the
normal case. In my standard installation, sys.path is

['', '/home/martin/work', '/usr/local/lib/python2.3',
'/usr/local/lib/python2.3/plat-linux2',
'/usr/local/lib/python2.3/lib-tk',
'/usr/local/lib/python2.3/lib-dynload',
'/usr/local/lib/python2.3/site-packages',
'/usr/local/lib/site-python']

So if I have 5 import hooks (including the default one), and I do
"import Fnorb" (which is in site-python), I get 36 hook calls before
the Fnorb package is found. For each element in sys.path, first the
default hook will fail, and then all additional hooks, then it
proceeds to the next element of sys.path. Quite expensive,
potentially.

Regards,
Martin