[Python-Dev] Relative package imports
mal at lemburg.com
Fri Jun 18 12:05:52 CEST 1999
Although David has already copy-posted a message regarding this issue
to the list, I would like to restate the problem to get a discussion
going (and then maybe take it to c.l.p for general flaming ;).
The problem we have run into on starship is that some well-known
packages have introduced naming conflicts leading to the unfortunate
situation that they can't be all installed on the same default
1. Zope has a module named DateTime which also is the base name of the
2. Both Zope and PIL have a top-level module named ImageFile.py
(different ones of course).
Now the problem is how to resolve these issues. One possibility
is turning Zope and PIL into proper packages altogether. To
ease this transition, one would need a way to specify relative
intra-package imports and a way to tell pickle where to look
The next problem we'd probably run into sooner or later is that
there are quite a few useful top-level modules with generic
names that will conflict with package names and other modules
with the same name.
I guess we'd need at least three things to overcome this situation once
and for all ;-):
1. Provide a way to do relative imports, e.g. a single dot could
be interpreted as "parent package":
from modD import * (works as usual: import A.B.modD)
from .modA import * (imports A.modA)
from ..modA import * (import the top-level modA)
2. Establish a general vendor based naming scheme much like the one
used in the Java world:
from org.python.core import time,os,string
from org.zope.core import *
from com.lemburg import DateTime
from com.pythonware import PIL
3. Add a way to prevent double imports of the same file.
This is the mayor gripe I have with pickle currently, because intra-
package imports often lead to package modules being imported
twice leading to many strange problems (e.g. splitting class
hierarchies, problems with isinstance() and issubclass(), etc.), e.g.
from org.python.core import UserDict
u = UserDict.UserDict()
v = UserDict.UserDict()
Now u and v will point to two different classes:
<class org.python.core.UserDict.UserDict at 80d3b48>
<class UserDict.UserDict at 80aed18>
4. Add some kind of redirection or lookup hook to pickle et al.
so that imports done during unpickling can be redirected to the
correct (possibly renamed) package.
Y2000: 196 days left
Python Pages: http://www.lemburg.com/python/
More information about the Python-Dev