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:

from ................antigravity import NGField  # [relative-beyond-top-level]

Correct code:

absolute_import.py:

from physic.antigravity import NGField

fix_the_relative_import.py:

# Right number of dots in the import: you needed 15 dots, not 16, duh.
# from ...............antigravity import NGField

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:

Created by the imports checker.