On Tue, Apr 2, 2013 at 6:20 AM, Kristján Valur Jónsson < krist...@ccpgames.com> wrote:
> I just ran into the issue described in > http://stackoverflow.com/questions/6351805/cyclic-module-dependencies-and-relative-imports-in-python > . > > This is unfortunate, because we have been trying to move towards relative > imports in order to aid flexibility in package and library design. > > The relative import syntax > > (from foo import bar) is a getattr type of lookup (i.e. import foo, then > get attr from it). > > This is in contrast with absolute import > > import foo.bar (get the module foo.bar from sys.modules or import it) > > bar = foo.bar > > > > the latter works with partially initialized modules, but not the former, > rendering two sibling modules unable to import each other using the > relative syntax. > This is really a quality-of-implementation issue in the import system rather than a core language design problem. It's just that those of us with the knowledge and ability to fix it aren't inclined to do so because circular imports usually (although not quite always) indicate a need to factor some common code out into a third support module imported by both of the original modules. At that point, the code is cleaner and more decoupled, and the uneven circular import support ceases to be a problem for that application. If you're interested in digging further, see http://bugs.python.org/issue992389 (this should also be a *lot* easier to fix now we're using importlib than it ever would have been while we were still relying on import.c) Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com