Consider the following case in Python 3.6:
basepackage
|---__init__.py
|---package
|---__init__.py
|---subpackage
|---__init__.py
|---module.py
Important detail: inside basepackage.package.__init__.py there's:
from basepackage.package.subpackage.module import AClass as AliasedClass
Now, let's say inside basepackage.package.subpackage.module.py we want to use:
import basepackage.package.subpackage.module as aliased_module [1]
The result is:
AttributeError: module 'basepackage' has no attribute 'package'
with a stack trace listing following culprit statements (in the below order):
from basepackage.package.subpackage.module import AClass as AliasedClass
import basepackage.package.subpackage.module as aliased_module
But if instead of [1] one'd like to use:
from basepackage.package.subpackage import module as aliased_module [2]
then everything works.
How is [1] so much different than [2] that the former results in an error and the latter not?