org.sonar.l10n.py.rules.python.S5549.html Maven / Gradle / Ivy
This rule raises an issue when a function is called with multiple values for the same parameter.
Why is this an issue?
When a function is called, it accepts only one value per parameter. The Python interpreter will raise a SyntaxError
when the same
parameter is provided more than once, i.e. myfunction(a=1, a=2)
.
Other less obvious cases will also fail at runtime by raising a TypeError
, when:
- An argument is provided by value and position at the same time.
- An argument is provided twice, once via unpacking and once by value or position.
Code examples
Noncompliant code example
def func(a, b, c):
return a * b * c
func(6, 93, 31, c=62) # Noncompliant: argument "c" is duplicated
params = {'c':31}
func(6, 93, 31, **params) # Noncompliant: argument "c" is duplicated
func(6, 93, c=62, **params) # Noncompliant: argument "c" is duplicated
Compliant solution
def func(a, b, c):
return a * b * c
func(c=31, b=93, a=6) # Compliant
params = {'c':31}
func(6, 93, **params) # Compliant
© 2015 - 2024 Weber Informatics LLC | Privacy Policy