module-import-not-at-top-of-file
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”...import os__version__ = "1"x = 1import sys
... pass
from __future__ import division
from __future__ import not_a_feature
...Configuration
Section titled “Configuration”python: lint: rules: module-import-not-at-top-of-file: warn # off (default), warn, errorSuppress one line with sudsy-disable-next-line module-import-not-at-top-of-file in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| ruff | E402 |
full |