2023-06-30 09:07:33 +02:00
This rule raises an issue when a function is called with multiple values for the same parameter.
2023-05-03 11:06:20 +02:00
== Why is this an issue?
2023-06-30 09:07:33 +02:00
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)`.
2021-04-28 18:08:03 +02:00
2023-06-30 09:07:33 +02:00
Other less obvious cases will also fail at runtime by raising a `TypeError`, when:
2021-04-28 18:08:03 +02:00
2023-06-30 09:07:33 +02:00
* 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.
2021-04-28 18:08:03 +02:00
2023-06-30 09:07:33 +02:00
=== Code examples
2020-06-30 12:50:28 +02:00
2023-06-30 09:07:33 +02:00
==== Noncompliant code example
2020-06-30 12:50:28 +02:00
2023-06-30 09:07:33 +02:00
[source,python,diff-id=1,diff-type=noncompliant]
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
----
2023-06-30 09:07:33 +02:00
==== Compliant solution
2021-04-28 18:08:03 +02:00
2023-06-30 09:07:33 +02:00
[source,python,diff-id=1,diff-type=compliant]
2020-06-30 12:50:28 +02:00
----
def func(a, b, c):
return a * b * c
2023-06-30 09:07:33 +02:00
func(c=31, b=93, a=6) # Compliant
params = {'c':31}
func(6, 93, **params) # Compliant
2020-06-30 12:50:28 +02:00
----
2021-04-28 18:08:03 +02:00
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== 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
2021-09-20 15:38:42 +02:00
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== 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)
----
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]