Skip to content
Sarj Code Standards

prefer-direct-import-module

Prefer static imports for eager module loads with a literal module name.

Why

Static imports expose known dependencies to readers and tooling without dynamic loader indirection.

Fix

Replace a fixed eager module load with a module-level import, preserving its binding: plugin = importlib.import_module('plugins.billing') becomes import plugins.billing as plugin. Use import plugins.billing when callers use the qualified module name; avoid a redundant alias for a single-component module. Keep dynamic loading when module selection or import timing requires it.

Examples

Before — flagged A known eager dependency is loaded dynamically
app.py
import importlib
plugin = importlib.import_module("plugins.billing")
After — preferred A static import preserves the module binding
app.py
import plugins.billing as plugin