.. _relative-beyond-top-level: relative-beyond-top-level / E0402 ================================= **Message emitted:** ``Attempted relative import beyond top-level package`` **Description:** *Used when a relative import tries to access too many levels in the current package.* **Problematic code:** .. literalinclude:: /data/messages/r/relative-beyond-top-level/bad.py :language: python **Correct code:** ``absolute_import.py``: .. literalinclude:: /data/messages/r/relative-beyond-top-level/good/absolute_import.py :language: python ``fix_the_relative_import.py``: .. literalinclude:: /data/messages/r/relative-beyond-top-level/good/fix_the_relative_import.py :language: python **Additional details:** Absolute imports were strongly preferred, historically. Relative imports allow you to reorganize packages without changing any code, but these days refactoring tools and IDEs allow you to do that at almost no cost anyway if the imports are explicit/absolute. Therefore, absolute imports are often still preferred over relative ones. **Related links:** - `Absolute vs. explicit relative import of Python module `_ - `Withdraw anti-recommendation of relative imports from documentation `_ Created by the `imports `__ checker.