This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author franck
Recipients franck
Date 2015-01-09.06:44:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1420785882.78.0.914141516682.issue23203@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2015-01-09 06:44:42francksetrecipients: + franck
2015-01-09 06:44:42francksetmessageid: <1420785882.78.0.914141516682.issue23203@psf.upfronthosting.co.za>
2015-01-09 06:44:42francklinkissue23203 messages
2015-01-09 06:44:42franckcreate