Open
Description
I was workig with autoapi and I got weird errors related to relative imports:
astroid.exceptions.TooManyLevelsError: Relative import with too many levels (2) for module 'not_found_404'
I finally realized that all the packages that were not specifcally containing a __init__.py
file were simply discarded due to this lines of code:
if level:
if self.package:
level = level - 1
package_name = self.name.rsplit(".", level)[0]
elif (
self.path
and not os.path.exists(os.path.dirname(self.path[0]) + "/__init__.py")
and os.path.exists(
os.path.dirname(self.path[0]) + "/" + modname.split(".")[0]
)
):
level = level - 1
package_name = ""
else:
package_name = self.name.rsplit(".", level)[0]
if level and self.name.count(".") < level:
raise TooManyLevelsError(level=level, name=self.name)
It turns out that to be considered a package, a folder MUST have an __init__.py
file. Can you expand a bit the "package" definition to any folder including python files ?
Metadata
Metadata
Assignees
Labels
No labels