[Python-Dev] Relative Package Imports

Jim Fulton jim@digicool.com
Tue, 14 Sep 1999 12:20:53 +0000

Tim Peters wrote:
> [MAL]
> > I agree that it's ugly to include the __ attribute in the module
> > namespace due to the possible circular reference (parent->module,
> > module->parent), but the patch I sent doesn't do this... or was
> > "ugly" referring to the two underscores looking strange ?
> >
> > Could you elaborate a bit on the reasons for dropping __ support ?
> There are two sections on why __ was dropped in
>     http://www.python.org/doc/essays/packages.html
> They don't refer to circularity, but to "limited use", "poor readability"
> and "awkwardness". 

Which are all quite subjective.

> A deeper reason may be hiding in the essay's "most
> packages will have a relative shallow substructure":  this is Guido <wink>,
> the man who invented two-level scoping, and class inheritance without a
> "super" hook back to the (anonymous) parent.  For all Python's dynamicism,
> it very much favors shallow, static name hierarchies.  I don't think it's
> coincidence that Python's own source code is in a two-level directory
> structure either!  The only #include with a ".." is in grammar.h, and there
> it's in a comment <wink>:
>     #include "bitset.h" /* Sigh... */
> So if we cut to the core here, I'd bet Guido doesn't object so much to
> relative imports as to the idea that anyone would go off and create a
> package structure so fractally convoluted that relative imports are strongly
> more attractive than naming the target package in full.
> Or maybe Guido doesn't care about that at all.  I do regardless.  I know
> Python's restrictions can grate, but in all, and in my repeated experience,
> they force you to rethink complicated designs and refactor them into simpler
> schemes that fit what Python is best at spelling.  Nesting packages 8 deep
> is clumsy now?  Damn straight, and I'm thankful for that:  the clumsier it
> is, the less gratuitous inherited complexity I'll have to deal with in my
> future lives <0.5 wink>.

Nobody has suggested building 8-level package hierarchies.  In fact,
the example I gave occured when a two-level package hierarchy was
used in a two-level hierarchy.

I don't think the Package structure of Zope is flawed *except*
for the fact that it is one level too *shallow*. The ability to
do relative imports would be very helpful for the work we're doing.


Jim Fulton           mailto:jim@digicool.com
Technical Director   (888) 344-4332              Python Powered!
Digital Creations    http://www.digicool.com     http://www.python.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for