Unused Private Method
ID |
python.unused_private_method |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Dead Code |
Language |
Python |
Tags |
CWE:561, dead-code, reliability |
Description
Reports a class method whose name is private by Python convention (one or two leading underscores, but not a dunder protocol method) and which is never called from inside the same compilation unit.
class Klass:
def __init__(self):
self._used()
def _used(self): # OK
return 0
def _dead(self): # FLAW — never called
return 1
Dunder methods (init, eq, etc.) are excluded — they are protocol methods. Decorated methods are excluded — decorators frequently register the method through reflection.