no-static-if-condition¶
Discourages if conditions which evaluate to a static value (e.g. or True, and False, etc).
Message¶
Your if condition appears to evaluate to a static value (e.g. or True, and False). Please double check this logic and if it is actually temporary debug code.
Valid examples¶
if my_func() or not else_func():
pass
if function_call(True):
pass
Show more
# ew who would this???
def true():
return False
if true() and else_call(): # True or False
pass
# ew who would this???
if False or some_func():
pass
if [*values]:
pass
if {**mapping}:
pass
Invalid examples¶
if True:
do_something()
if 1:
do_something()
if None:
do_something()
Show more
if "":
do_something()
if 0.0:
do_something()
if -1:
do_something()
if b"":
do_something()
if ...:
do_something()
if [*values, sentinel]:
do_something()
if {**mapping, "sentinel": sentinel}:
do_something()
if crazy_expression or True:
do_something()
if crazy_expression and False:
do_something()
if crazy_expression and not True:
do_something()
if crazy_expression or not False:
do_something()
if crazy_expression or (something() or True):
do_something()
if crazy_expression and (something() and (not True)):
do_something()
if crazy_expression and (something() and (other_func() and not True)):
do_something()
if (crazy_expression and (something() and (not True))) or True:
do_something()
async def some_func() -> none:
if (await expression()) and False:
pass