E0402 relative-beyond-top-level¶
- Message
'Attempted relative import beyond top-level package'
- Description
Used when a relative import tries to access too many levels in the current package.
Example¶
Given the following files
# mypkg/__init__.py
from . import mymod
# mypkg/mymod.py
from . import myothermod
# ...
# mypkg/myothermod.py
from .. import somemod
# ...
The two relative imports in mypkg/__init__.py
and mypkg/mymod.pg
work
because they only import from the current level. The import in
mypkg/myothermod.py
though tries to import from the parent of mypkg
which is impossible because mypkg
is the top-level package and does not
have a parent.
Running Pylint locally? In your CI?
There is a better way! Run PyCodeQual & get Pylint findings with history, diffs and statistics.

Click here to find out more.