Skip to content

module-import-not-at-top-of-file

Pythonstyleno fixdefault: off

Reports an import at module level after code. Docstrings, __all__, blocks (if, try) and sys.path or os.environ setup do not count as code.

Imports at the top show what the module depends on, in one place, and a name is never used before it is imported. An import in the middle hides a dependency and runs later than a reader expects.

To fix, move the import to the top of the file.

Reported
...
import os
__version__ = "1"
x = 1
import sys
...
pass
from __future__ import division
from __future__ import not_a_feature
...
python:
lint:
rules:
module-import-not-at-top-of-file: warn # off (default), warn, error

Suppress one line with sudsy-disable-next-line module-import-not-at-top-of-file in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff E402 full