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.
Definition
Section titled “Definition”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.
Evidence
Section titled “Evidence”Each finding cites the constant definition and exact importing statement. The Boolean result identifies one proven cross-module project constant import.
Exceptions
Section titled “Exceptions”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.
Examples
Section titled “Examples”Bad
`from .service import _TIMEOUT` and `from .service import TIMEOUT` both expose project constantstate 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.
References
Section titled “References”- 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