Skip to content

PY-CONS0001 · public_module_constant

Find project module constants exposed without a leading underscore.

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

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.

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.

Interpreter-reserved dunder names are excluded. A deliberate public constant API can disable this preference for its defining file.

Bad

`DEFAULT_TIMEOUT = 30` exposes project-owned constant state from its module.
Good

_DEFAULT_TIMEOUT = 30 keeps the constant private to its defining module.

  • 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