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.

K

From: bcan...@gmail.com [mailto:bcan...@gmail.com] On Behalf Of Brett Cannon
Sent: 1. apríl 2013 22:38
To: Kristján Valur Jónsson
Cc: python-dev@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.


_______________________________________________
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

Reply via email to