Mailing List Archive

Walking up the package hierarchy
Hi everybody,

while I'm still thinking about writing the import manager, here
is a patch that implements the walk-up-the-hierarchy import scheme
that got so much positive feedback. I'm intending to use this
implementation as proof of concept for the switch to my new
package structure, but wouldn't mind seeing something like it
the distribution as well ;-)

It changes the default import mechanism to work like this:

>>> import d
try a.b.c.d
try a.b.d
try a.d
try d
fail

instead of just doing the current two-level lookup:

>>> import d
try a.b.c.d
try d
fail

As a result, relative imports referring to higher level packages
work out of the box without any ugly underscores in the import name.
Plus the whole scheme is pretty simple to explain and straightforward.

Since the patch is so small, I attached it to this mail. Hope
you don't mind. The ZIP archive also contains a sample package
which demonstrates the feature. Run Python with -v flag to see how
the new scheme works.

Feedback is most welcome. I am especially interested whether the
scheme breaks any existing packages.

--
Marc-Andre Lemburg
______________________________________________________________________
Y2000: 81 days left
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/
Re: Walking up the package hierarchy [ In reply to ]
Strange... I would have thought that this new patch would stir up
some cheers or opposition. Has anyone tried it in some real apps ?

It would be interesting to see whether it breaks any code in e.g.
packages such as Pmw, PIL, Zope's packages or NumPy. It doesn't
break anything for my packages or apps.

> It changes the default import mechanism to work like this:
>
> >>> import d
> try a.b.c.d
> try a.b.d
> try a.d
> try d
> fail
>
> instead of just doing the current two-level lookup:
>
> >>> import d
> try a.b.c.d
> try d
> fail

--
Marc-Andre Lemburg
______________________________________________________________________
Y2000: 79 days left
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/
Re: Walking up the package hierarchy [ In reply to ]
M.-A. Lemburg wrote:
>
> Strange... I would have thought that this new patch would stir up
> some cheers or opposition. Has anyone tried it in some real apps ?

Not yet, but this looks better as a default search path.

>
> It would be interesting to see whether it breaks any code in e.g.
> packages such as Pmw, PIL, Zope's packages or NumPy. It doesn't
> break anything for my packages or apps.

JimF, /F, Guido and other package maintainers could do you a favor
by trying your patch ;-) and give us some real feedback on this.

--
Vladimir MARANGOZOV | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252