A typical code smell known as unused function parameters refers to parameters declared in a function but not used anywhere within the function’s
body. While this might seem harmless at first glance, it can lead to confusion and potential errors in your code. Disregarding the values passed to
such parameters, the function’s behavior will be the same, but the programmer’s intention won’t be clearly expressed anymore. Therefore, removing
function parameters that are not being utilized is considered best practice.
Exceptions
This rule ignores overriding methods.
class C(B):
def do_something(self, a, b): # no issue reported on b
return self.compute(a)
This rule also ignores variables named with a single underscore _
. Such naming is a common practice for indicating that the variable
is insignificant.
def do_something(a, _): # no issue reported on _
return compute(a)
The rule also won’t raise an issue if the parameter is referenced in a docstring or a comment:
class MyClass:
def do_something(self, my_param): # no issue reported
# Overrides may use my_param to ...
return compute(a)
class MyClass:
def do_something(self, my_param): # no issue reported
"""Overrides may use my_param to ..."""
return compute(a)