All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.py.rules.python.S1172.html Maven / Gradle / Ivy

There is a newer version: 4.23.0.17664
Show newest version

Why is this an issue?

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)

How to fix it

Having unused function parameters in your code can lead to confusion and misunderstanding of a developer’s intention. They reduce code readability and introduce the potential for errors. To avoid these problems, developers should remove unused parameters from function declarations.

Code examples

Noncompliant code example

def do_something(a, b): # "b" is unused
  return compute(a)

Compliant solution

def do_something(a):
  return compute(a)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy