Naming Conventions

ID

python.naming_conventions

Severity

info

Remediation Complexity

trivial

Remediation Risk

medium

Remediation Effort

low

Resource

Naming Convention

Language

Python

Tags

code-style, naming

Description

Reports a variable or attribute assignment whose target name is neither snake_case nor UPPER_CASE. PEP 8 reserves snake_case (lower-case-with-underscores) for ordinary variables and UPPER_CASE for module- and class-level constants; mixed-case targets (PascalCase, camelCase, …​) blur the kind of binding at a glance and are flagged.

MaxRetries = 5            # FLAW — should be MAX_RETRIES or max_retries
DEFAULT_TIMEOUT = 30      # OK   — UPPER_CASE constant
max_retries = 5           # OK   — snake_case variable

class Cfg:
    badAttr = 0           # FLAW
    SENTINEL = object()   # OK

    def method(self):
        BadLocal = 1      # FLAW
        local_thing = 2   # OK

Rationale

PEP 8 is the dominant style baseline across the Python ecosystem. Adhering to the two canonical shapes (snake_case for mutables, UPPER_CASE for constants) lets readers distinguish variables, constants, classes, and functions purely from naming, without having to inspect each binding’s surroundings.

This rule is the companion to python.naming_class (CapWords for classes) and python.naming_method (snake_case for callables). Together they cover every named declaration at module, class, and function scope.

Remediation

Rename the assignment target to either snake_case (variables) or UPPER_CASE (constants). Leading and trailing underscores are preserved by the check, so internal, private, MAX_LIMIT, and dunder names (version__) all remain valid.

Tuple- and list-unpacking targets are inspected individually — rename only the offending element.