rspec/rules/S5781/rule.adoc

33 lines
660 B
Plaintext
Raw Normal View History

2020-06-30 12:50:28 +02:00
A set cannot have two identical values. When a value is repeated in a set literal, only the last occurence will remain. Thus duplicate values should be either modified or removed.
2021-02-02 15:02:10 +01:00
2020-06-30 12:50:28 +02:00
This rule raises an issue when the same value is used multiple times as a value in a set literal.
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:50:28 +02:00
----
{"one", "two", "one"} # Noncompliant
def func(a1, a2, a3):
{a1, a2, a1} # Noncompliant.
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:50:28 +02:00
----
{"one", "two", "three"}
def func(a1, a2, a3):
{a1, a2, a3}
----
== See
* https://docs.python.org/3/reference/expressions.html#set-displays[Python documentation - Set displays]