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

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

There is a newer version: 4.23.0.17664
Show newest version

This rule raises an issue when a comparison to None is invariant.

Why is this an issue?

Checking if a variable or parameter is None should only be done when you expect that it can be None. Doing so when the variable is always None or never None is confusing at best. At worse, there is a bug and the variable is not updated properly.

This rule raises an issue when expressions X is None, X is not None, X == None or X != None are constant, i.e. X is always None or never None.

Code examples

Noncompliant code example

def foo():
    my_var = None
    if my_var == None:  # Noncompliant: always True.
        ...

Compliant solution

def foo(my_var):
    if my_var == None:
        ...

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy