Skip to content

PY-CONS0002 · cross_module_project_constant_import

Detect a project-owned constant imported outside its defining module.

This is a deterministic rule for python. Read its implementation.

Detect public or single-underscore uppercase constants defined by top-level assignments. Resolve project-relative and absolute from imports against those definitions. Report every import from a different project module. Constants remain private implementation details rather than becoming shared state through a constants.py module.

Each finding cites the constant definition and exact importing statement. The Boolean result identifies one proven cross-module project constant import.

Third-party symbols and imports guarded by TYPE_CHECKING are excluded. Wildcard imports, dynamically created names, and attribute access through an imported module are not inferred. Imports inside the defining module are not cross-module uses.

Bad

`from .service import _TIMEOUT` and `from .service import TIMEOUT` both expose project constant
state across a module boundary.
Good

_TIMEOUT remains in service.py, while consumers call a public operation that owns the relevant behavior. from third_party import TIMEOUT is outside the project definition graph.

  • Cites “PEP 8, Style Guide for Python Code”, constants naming convention. Open reference
  • Cites “The Python Language Reference”, import system reference. Open reference
  • Cites “PEP 8, Style Guide for Python Code”, public and internal interfaces. Open reference