PY-CONS0001 · public_module_constant
Find project module constants exposed without a leading underscore.
This is a deterministic rule for python. Read its implementation.
Definition
Section titled “Definition”Inspect top-level assignments and annotated assignments whose names use the public uppercase
constant convention. Report names such as TIMEOUT and JSON_ADAPTER. Project file constants
are implementation details by default and should use one leading underscore. Cross-module
imports are handled separately by the project constant import rule.
Evidence
Section titled “Evidence”Each finding identifies the public constant declaration and its exact source line. Private uppercase constants, ordinary variables, instance attributes, class attributes, and lowercase implementation state are not reported. The value is the number of public uppercase module constants.
Exceptions
Section titled “Exceptions”Interpreter-reserved dunder names are excluded. A deliberate public constant API can disable this preference for its defining file.
Examples
Section titled “Examples”Bad
`DEFAULT_TIMEOUT = 30` exposes project-owned constant state from its module.
Good_DEFAULT_TIMEOUT = 30 keeps the constant private to its defining module.
References
Section titled “References”- Cites “PEP 8, Style Guide for Python Code”, constants naming convention. Open reference
- Cites “PEP 8, Style Guide for Python Code”, public and internal interfaces. Open reference