Bug? with circular imports of packaged modules.

Chris Armstrong carmstro at twistedmatrix.com
Mon Jun 11 15:58:44 CEST 2001

Hello all. I've been refactoring a few Twisted Python modules into packages,
and have run into some problems with modules that import each other. Usually,
this is not a problem, but the TPy coding standard states (well, did state, 
until we found this "bug") that no sibling imports should be allowed. Which 
means, instead of twisted.web.server doing 'import html', it has to do 
'from twisted.web import html'. The reason for this is to prevent ambiguous
imports. The problem is, if the html module also did 
'from twisted.web import server', python would raise an ImportError saying 
'cannot import name server' in the html.py module. This doesn't make sense,
since the modules will import each other if they don't import from the package,
and package imports work normally as long as they're not circular.

So, I'm changing the second-level packages in TPy to just do sibling imports for
now, but it'd be nice to see this problem corrected in future Python versions.
If anyone has any suggestions, I appreciate them.

More information about the Python-list mailing list