[Python-Dev] relative import circular problem

Kristján Valur Jónsson kristjan at ccpgames.com
Tue Apr 2 11:28:17 CEST 2013

Right, as I explained in my reply to Barry, I was imprecise.
But the “from X import Y” is the only way to invoke relative imports, where X can have leading dots.
This syntax places the constraint on X that Y is actually an attribute of X at this time, where
“import X.Y” does not.
So, even without the leading dots issue, they are not equivalent.  You run into the same
circular dependency problem without using relative imports if trying to use the
“from X import Y” where X is an absolute name.


From: bcannon at gmail.com [mailto:bcannon at gmail.com] On Behalf Of Brett Cannon
Sent: 1. apríl 2013 22:38
To: Kristján Valur Jónsson
Cc: python-dev at python.org
Subject: Re: [Python-Dev] relative import circular problem

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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130402/4d21fca9/attachment.html>

More information about the Python-Dev mailing list