rspec/rules/S4143/python/rule.adoc

21 lines
766 B
Plaintext
Raw Normal View History

2020-06-30 12:49:37 +02:00
It is highly suspicious when a value is saved in a collection for a given key or index and then unconditionally overwritten. Such replacements are likely errors.
2021-01-27 13:42:22 +01:00
This rule raises an issue when the https://docs.python.org/3/reference/datamodel.html#object.__setitem__[``++__setitem__++``] method of the same object is called multiple times with the same index, slice or key without any other action done between the calls.
2020-06-30 12:49:37 +02:00
== Noncompliant Code Example
----
def swap(mylist, index1, index2):
tmp = mylist[index2]
mylist[index2] = mylist[index1]
mylist[index2] = tmp # Noncompliant
list2 = [0,1,2,3,4,5,6,7,8,9]
list2[3:5] = [42,42]
list2[3:5] = [42,42] # Noncompliant
mymap = {'a': {}}
mymap['a']['b'] = 42
mymap['a']['b'] = 42 # Noncompliant
----