[Zope3-dev] Importing

Guido van Rossum guido@python.org
Wed, 12 Dec 2001 07:49:48 -0500


> > Ah, the relative import fallacy.  Why is it required to be able to
> > reparent a package without changing the source?  
> 
> So that a package may be re-used as a sub-package in another package without
> having to re-write or otherwise fudge all the import statements in the import
> package.

I don't find that an important requirement.

> well, if i have:
> 
> /package1/
> /package1/package2a/modulea
> /package1/package2a/package2b/mobuleb
> 
> ...then when package 2 is being used on its own, I could do the following in
> moduleb:

What do you mean by "on its own?".  I'm afraid that you mean that
/package1 is on sys.path?  That's evil!

> from package2a.modulea import someclass
> 
> However, as soon as package2a is installed as a sub-package of package1, then
> I'd have to change that import statement to:
> 
> from package1.package2a.modulea import someclass
> 
> ...or am I missign something?

No, we just disagree on the desirability of all this.  I think
"fixing" this in Python would be wrong, and leading to more confusion
(for the *reader*, it's hard enough to figure out where to look for
modules without multiple levels of relative import).  But others have
occasionally asked for this too.  We should make it a PEP and reject
it for clarity.  (PEP 667 anyone?)

--Guido van Rossum (home page: http://www.python.org/~guido/)