New submission from Franck Michea: Hi, for those of you that prefer to read an example, you can read that commented demonstration of the bug[1].
Today I discovered what I think is a bug in the import system. Here is the basic setup: We have three nested packages: foo -> bar -> baz. The bar package imports foo.bar.baz. We try to import foo.bar. This works well unless we try to alias the foo.bar.baz import in foo.bar with the "import ... as ..." syntax. In that case the file will be read and executed but when we get out of the import statement, then python throws: Traceback (most recent call last): File "<string>", line 1, in <module> File "foo_alias_mod/bar/__init__.py", line 1, in <module> import foo_alias_mod.bar.baz as name_does_not_matter AttributeError: 'module' object has no attribute 'bar' This works whether baz is a package or a module actually. It does not matter if it's from the interpreter, or in a file, ... I've seen it trigger with 2.7.5, 2.7.9, 3.4.5, tip, so I guess this has been here for some time. Please read the link below for a complete demo, and you can always download the tarball[2] to test yourself. [1]: Commented demonstration: http://98810f8c06.net/wtf_python.html [2]: Tarball for test: http://98810f8c06.net/wtf_python-demo.tar.bz2 ---------- components: Interpreter Core messages: 233719 nosy: franck priority: normal severity: normal status: open title: Aliasing import of sub-{module,package} from the package raises AttributeError on import. _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23203> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com