Why is this an issue?
If a boolean expression doesn’t change the evaluation of the condition, then it is entirely unnecessary, and can be removed. If it is gratuitous
because it does not match the programmer’s intent, then it’s a bug and the expression should be fixed.
Noncompliant code example
def f(b):
a = True
if a: # Noncompliant
do_something()
if a and b: # Noncompliant; "a" is always "True"
do_something()
Compliant solution
def f(b):
a = True
if foo(a):
do_something()
if b:
do_something()
Resources