[Import-sig] Re: (Serious?) package namespace problem (and a proposal)

M.-A. Lemburg mal@lemburg.com
Fri, 30 Jun 2000 15:36:14 +0200


Gordon McMillan about relative imports:
> 
> > > Their main feature is "ease of use", which can be pejoratively
> > > cast as "programmer laziness".
> >
> > No no no... the feature can be put to clever use *within*
> > packages. If you always have to specify the absolute path
> > to the modules, you will have a hard time moving packages
> > under new umbrella packages -- something which gets done every
> > now and then. Not having relative imports then causes a lot of
> > breakage.
> 
> And how does anything you've said contradict (as in "No no
> no") anything I said?

Simple: relative imports are not an artifact of "programmer laziness".
What goes on inside a package is up to the programmer. How
it can be installed is part of the published package interface.

With the current setup, the only way to install a package is
to make it top-level. Relative imports would make it possible
to also install the package under some other top-level
package (and it would still work as before).

> It makes your life easier. It does not make your users' lives
> easier.
> 
> Or have you missed the fact that I've had to explain on c.l.py
> (at least 3 times) that various strange problems with mx
> packages stem from misunderstanding how to install them on
> the path?

I know that people have problems with packages in general
(not only the mx ones, although these were among the first
to use the mechanism). Most of these are related to PYTHONPATH
and their understanding of how imports work in Python.

With distutils all of these problem will hopefully go
away...

> When "import mxDateTime" doesn't throw an exception,
> people for some reason expect to be able to *use*
> mxDateTime.

Could you explain this ? "import mxDateTime" will normally only
work inside the package (or if the user ran "make install"
instead of just "make"). All other cases should yield
an import error.

Note that some time ago I proposed to add relative imports
by changing the lookup mechanism to something more easily
understood. Basically what happens is that import searches
up the package hierarchy if can't find the module at the
current level -- very simple, very effective.

The proposal was tossed around a few times and nothing
happened. Perhaps I should look into the new imputil
design and recheck whether I can add something there...

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/