Unused Method Parameter
ID |
python.unused_method_parameter |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Dead Code |
Language |
Python |
Tags |
dead-code, reliability |
Description
Reports a function or method parameter that is never read in the body. Unused parameters are usually leftovers from a refactor or scaffolding from an interface-driven contract that has since changed.
def f(a, b): # FLAW on b — never read
return a
def g(a, _ignored): # OK — leading underscore is intentional
return a
self / cls are excluded (Python’s calling convention requires them). Dunder methods (init, eq, etc.) are excluded — their signature is fixed by the protocol. Decorated functions are excluded — decorators commonly mandate the signature. Methods on classes whose body reads no parameter at all are excluded — that’s almost always an interface stub or override.
Rationale
An unused parameter is a hint to the reader that something is wrong with the function’s contract: either the parameter was meant to be used and isn’t, or it was kept for backward compatibility and should be removed if no caller relies on it.
Remediation
-
Delete the parameter from the signature and call sites.
-
Rename to
_nameto signal "intentional, do not use". -
Restore the missing read if the typo dropped it.