Brett Cannon added the comment:

It's because you have a nested circular import. When you import 
package2.subpackage from within package2.subpackage you're in package2 
importing package2 and also in package2.subpackage importing 
package2.subpackage.

You can solve your problem by doing either ``from package2.subpackage import 
foo`` for ``from . import foo`` as that lets package2.subpackage be imported 
entirely on its own before attempting package2.subpackage.foo and thus letting 
the circular loop unroll and have the right attributes set since the attributes 
of a module for a package are set after the import completes.

Might be annoying, but tweaking this would probably break code if changed as 
it's very old semantics to set the attribute of a module on a package after 
other imports complete. This is also not a problem as long as you don't do this 
in an __init__ (e.g. importing package2.subpackage.bar from 
package2.subpackage.foo is not a problem).

----------
nosy: +brett.cannon
resolution:  -> wont fix
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18145>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to