[Python-Dev] relative import circular problem
brett at python.org
Tue Apr 2 00:37:53 CEST 2013
On Mon, Apr 1, 2013 at 4:20 PM, Kristján Valur Jónsson <
kristjan at ccpgames.com> wrote:
> I just ran into the issue described in
> 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
Or ``import foo.bar as 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.
Clarification on terminology: the ``from .. import`` syntax is in no way
relative. Relative imports use leading dots to specify relative offsets
from your current position (i.e. as Barry said). It's more of a syntax for
facilitating binding long names (e.g. foo.bar) to shorter names (bar). It's
just unfortunate that it can lead to circular import issues when people
start pulling in objects off of modules instead of modules alone.
> as far as I know, relative imports are only supported using the former
> (import from) syntax. Are there any plans to alleviate this by allowing
> proper relative imports? After all, relative imports and packages go hand
> in hand.
No, there are no plans to either tweak ``from ... import`` statements nor
introduce a new syntax to deal help alleviate circular imports.
> Python-Dev mailing list
> Python-Dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev