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

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

A dead store happens when a local variable is assigned a value that is not read by any subsequent instruction. Calculating or retrieving a value only to then overwrite it or throw it away, could indicate a serious error in the code. Even if it's not an error, it is at best a waste of resources. Therefore all calculated values should be used.

Noncompliant Code Example

def func(a, b, compute):
    i = a + b  # Noncompliant; calculation result not used before value is overwritten
    i = compute()  # Noncompliant; the value is not used before leaving the function

Compliant Solution

def func(a, b, compute):
    i = a + b
    i += compute()
    return i

Exceptions

This rule ignores initializations to -1, 0, 1, None, True, False and "".

No issue will be raised on unpacked variables.

See





© 2015 - 2025 Weber Informatics LLC | Privacy Policy