[issue18145] Strange behavior when importing internal modules in the __init__.py of a submodule

2013-06-05 Thread Antoine Pietri
New submission from Antoine Pietri: I just found a very strange bug today, and it took me like two hours to figure out the problem. We first create a package "package", which contains an __init__.py, which makes an absolute import of package/foo.py (import package.foo), which makes an absolut

[issue18145] Strange behavior when importing internal modules in the __init__.py of a submodule

2013-06-05 Thread Brett Cannon
Changes by Brett Cannon : -- versions: +Python 2.7, Python 3.4 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue18145] Strange behavior when importing internal modules in the __init__.py of a submodule

2013-06-05 Thread Brett Cannon
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 `

[issue18145] Strange behavior when importing internal modules in the __init__.py of a submodule

2013-06-05 Thread Antoine Pietri
Antoine Pietri added the comment: Okay, maybe my message was unclear. I figured out on my own how to work around this issue (for instance using relative imports), the main problem for me is that this issue is very difficult to debug. The "import" statement should at least fail with a more expl

[issue18145] Strange behavior when importing internal modules in the __init__.py of a submodule

2013-06-05 Thread Brett Cannon
Brett Cannon added the comment: It can't. The AttributeError is in the executing module code, not import itself so there is no reasonable way to tell that the failure was because of a circular loop in the import and not simply because you tried to get at an attribute that doesn't exist for som