rspec/rules/S5549/python/rule.adoc

51 lines
1.2 KiB
Plaintext
Raw Normal View History

When a function is called, it accepts only one value per parameter. Python interpreters will raise a SyntaxError when they see something like ``++myfunction(a=1, a=2)++``, but there are other cases which will only fail at runtime:
* An argument is provided by value and position at the same time.
* Some arguments are provided via unpacking and the same argument is provided twice.
This rule raises an issue when a function is called with multiple values for the same parameter.
2020-06-30 12:50:28 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,python]
2020-06-30 12:50:28 +02:00
----
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
----
2020-06-30 12:50:28 +02:00
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,python]
2020-06-30 12:50:28 +02:00
----
def func(a, b, c):
return a * b * c
print(func(c=31, b=93, a=6)) # Compliant
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]