All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.py.rules.python.S4143.html Maven / Gradle / Ivy

There is a newer version: 4.23.0.17664
Show newest version

Why is this an issue?

Storing a value inside a collection at a given key or index and then unconditionally overwriting it without reading the initial value is a case of a "dead store".

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

This practice is redundant and will cause confusion for the reader. More importantly, it is often an error and not what the developer intended to do.





© 2015 - 2024 Weber Informatics LLC | Privacy Policy