
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
73 lines
1.6 KiB
Plaintext
73 lines
1.6 KiB
Plaintext
== Why is this an issue?
|
|
|
|
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.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,python]
|
|
----
|
|
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
|
|
|
|
[source,python]
|
|
----
|
|
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)
|
|
|
|
=== Message
|
|
|
|
{xxx} argument is duplicated in {function} call
|
|
|
|
|
|
=== Highlighting
|
|
|
|
Primary: the first appearance of duplicated argument
|
|
|
|
Secondary:
|
|
|
|
* location: the others argument duplicated
|
|
** message: argument also passed here
|
|
|
|
* location: the signature of the called function
|
|
* message: function definition
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 23 Apr 2020, 17:28:22 Nicolas Harraudeau wrote:
|
|
The following use case was removed because it is a syntax error and we don't want to target those:
|
|
|
|
----
|
|
func(c=31, b=93, c=62)
|
|
----
|
|
|
|
endif::env-github,rspecator-view[]
|