Naming Method
ID |
python.naming_method |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Python |
Tags |
code-style, naming |
Description
Reports a function or method declaration whose name is not snake_case. PEP 8 specifies snake_case for functions and methods. Dunder protocol methods (init, str, …) are excluded; testXxx style is excluded for unittest compatibility.
def fooBar(): # FLAW — should be foo_bar
...
def good_function(): # OK
...
class WithDunder:
def __init__(self): # OK — dunder
pass
class TestThing:
def testSomething(self): # OK — unittest-style
pass
Rationale
snake_case for callables is the dominant convention across the Python ecosystem. Mixed casing makes it harder for readers to tell at a glance whether an identifier is a function, class, or constant.
Remediation
Rename the function or method to snake_case. Underscores are allowed at start (private convention) and end (avoiding builtin shadowing, e.g. id_ to dodge the id builtin).