[issue992389] attribute error after non-from import

Torsten Bronger report at bugs.python.org
Sun Apr 13 10:15:36 CEST 2008


Torsten Bronger <bronger at physik.rwth-aachen.de> added the comment:

I dare to make a follow-up although I have no idea at all about the
internal processes in the Python interpreter.  But I've experimented
with circular imports a lot recently.  Just two points:

First, I think that circular imports don't necessarily exhibit a
sub-opimal programming style.  I had a large parser module which I just
wanted to split in order to get handy file sizes.  However, the parser
parses human documents, and layout element A defined in module A may
contain element B from module B and vice versa.  In a language with
declarations, you just include a big header file but in Python, you end
up with circular imports.  Or, you must stay with large files.

So, while I think that this clean error message Nick suggests is a good
provisional solution, it should not make the impression that the
circular import is a flaw by itself.

And secondly, the problem with modules that are not yet populated with
objects is how circular imports have worked in Python anyway.  You can
easily cope with it by not referencing the imported module's objects in
the top-level code of the importing module (but only in functions and
methods).

____________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue992389>
____________________________________


More information about the Python-bugs-list mailing list