Skip to content

Simplify Boolean Comparison

Sourcery refactoring id: simplify-boolean-comparison

Description:

Removes unnecessarily verbose boolean comparisons

Before:

need_hat = not is_raining
if need_hat == True:
    put_on_hat()

After:

need_hat = not is_raining
if need_hat:
    put_on_hat()

Explanation:

It is unnecessary to compare boolean values to True or False in the test of an if condition. Removing these unnecessary checks makes the code slightly shorter and easier to parse.

Was this page helpful?