Unused Import

ID

python.unused_import

Severity

low

Remediation Complexity

auto_fix

Remediation Risk

low

Remediation Effort

low

Resource

Dead Code

Language

Python

Tags

dead-code, imports, reliability

Description

Reports an import or from … import statement that brings in a name never referenced in the rest of the module.

import os                              # FLAW — os never used
from typing import List                # FLAW — List never used

import sys                              # OK
print(sys.path)

The rule skips wildcard imports (from x import * is covered by python.avoid_star_import), names beginning with _ (intentional), and modules that define all (the import is likely re-exported even when the file itself does not read it).

Rationale

Unused imports increase startup time, mask dependency drift in a codebase, and confuse readers about what a module actually relies on.

Remediation

  • Delete the import.

  • If the import is only there for its side-effects (e.g. import readline to wire up GNU readline), the surface API is silent — leave a comment.

  • If you want the symbol re-exported, add it to all — the rule will then suppress.