Naming Class
ID |
python.naming_class |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Python |
Tags |
code-style, naming |
Description
Reports a class declaration whose name is not CapWords (PascalCase). PEP 8 specifies CapWords for class names. A single leading underscore is allowed for module-internal classes.
class my_class: # FLAW — should be MyClass
pass
class GoodClass: # OK
pass
class HTTPClient: # OK — initialism preserved
pass
class _PrivateClass: # OK — module-internal
pass
Rationale
CapWords for classes is universal across the Python ecosystem; deviating costs readers a moment of disorientation at every site that touches the class.
Remediation
Rename the class to CapWords. Keep initialisms uppercased (HTTPClient, not HttpClient) — PEP 8 leaves the choice to the project but the dominant convention is to preserve them.