New submission from David Hagen:

Consider the following Python project:

bugtest/
  __init__.py (Contents: from .foo import *)
  foo/
    __init__.py (Contents: from .foo import *)
    foo.py (Contents: <empty file>)

Then in a Python session, the following line executes without error (as 
expected):

>>> import bugtest.foo.foo

However, the following line gives an error (not as expected):

>>> import bugtest.foo.foo as bar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'bugtest.foo.foo' has no attribute 'foo'

Note that this behavior is dependent on the folder foo and the file foo.py 
having the same base name. But is not dependent on actually trying to import 
bugtest.foo.foo. Trying to import bugtest.foo.baz will also fail as long as 
bugtest.foo.foo exists.

It is also dependent on the __init__.py files importing something from their 
respective submodules.

----------
messages: 301614
nosy: David Hagen
priority: normal
severity: normal
status: open
title: `import as` does not work when module has same same as parent module
type: behavior
versions: Python 3.5, Python 3.6

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

Reply via email to