[issue31385] `import as` does not work when module has same same as parent module

Serhiy Storchaka report at bugs.python.org
Thu Sep 7 17:48:09 EDT 2017


Serhiy Storchaka added the comment:

In 3.7 the error is different:

>>> import bugtest.foo.foo as bar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'foo' from 'bugtest.foo.foo' (/home/serhiy/py/cpython/bugtest/foo/foo.py)

The statement "from .foo import *" in bugtest/__init__.py imports name foo from the module bugtest.foo and rewrites the attribute foo.

>>> import bugtest
>>> bugtest.foo
<module 'bugtest.foo.foo' from '/home/serhiy/py/cpython/bugtest/foo/foo.py'>

This behavior is the same in all supported Python versions.

----------
nosy: +brett.cannon, eric.snow, ncoghlan, serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31385>
_______________________________________


More information about the Python-bugs-list mailing list