[Python-ideas] Avoid (was: Improve) circular import

Victor Varvariuc victor.varvariuc at gmail.com
Tue Apr 10 13:24:18 CEST 2012


On Tue, Apr 10, 2012 at 12:55 PM, Oleg Broytman <phd at phdru.name> wrote:

> My opinion is - restructure code to avoid circular import instead of
hacking import machinery.

It's not feasible sometimes.

See:
http://stackoverflow.com/questions/1556387/circular-import-dependency-in-python

Yes, they could be considered the same package. But if this results in a
massively huge file then it's impractical. I agree that frequently,
circular dependencies mean the design should be thought through again. But
there ARE some design patterns where it's appropriate (and where merging
the files together would result in a huge file) so I think it's dogmatic to
say that the packages should either be combined or the design should be
re-evaluated. – Matthew Lund Dec 1 '11 at 21:49


> Why does a submodule import the entire package instead of importing
just root?

import tree, sys
print("tree.branch: 'root' in dir(tree) ->", 'root' in dir(tree))
print("tree.branch: 'tree.root' in sys.modules ->", 'tree.root' in
sys.modules)

Ignore this part - my fault.

--
*Victor*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120410/b2c7c475/attachment.html>


More information about the Python-ideas mailing list