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

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

The newest version!

Why is this an issue?

Functions, methods, or lambdas with a long parameter list are difficult to use, as maintainers must figure out the role of each parameter and keep track of their position.

def set_coordinates(x1, y1, z1, x2, y2, z2): # Noncompliant
    # ...

The solution can be to:

  • Split the function, method, or lambda into smaller ones
# Each function does a part of what the original set_coordinates function was doing, so confusion risks are lower
def set_origin(x, y, z):
   # ...

def set_size(width, height, depth):
   # ...
  • Find a better data structure for the parameters that group data in a way that makes sense for the specific application domain
@dataclass
class Point: # In geometry, Point is a logical structure to group data
    x: int
    y: int
    z: int

def set_coordinates(p1: Point, p2: Point):
    # ...

This rule raises an issue when a function, a method, or a lambda has more parameters than the provided threshold.

Exceptions

The first argument of non-static methods, i.e., self or cls, is not counted as it is mandatory and passed automatically.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy