Skip to content
Sarj Code Standards

no-sys-path-mutation

Do not mutate the interpreter import search path.

Why

Changing the process-wide import search path makes import resolution depend on execution order and can shadow installed packages.

Fix

Install the package and use explicit package imports. A required interpreter bootstrap boundary needs an explained local suppression.

Examples

Before — flagged Import resolution depends on process-wide mutation
service/bootstrap.py
import sys
sys.path.insert(0, "/opt/application")
After — preferred Inspecting a snapshot does not change import resolution
service/bootstrap.py
import sys
search_path = tuple(sys.path)