Skip to content

Simplify Boolean Comparison

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Sourcery refactoring id: simplify-boolean-comparison

Section titled “Sourcery refactoring id: simplify-boolean-comparison”

Removes unnecessarily verbose boolean comparisons

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

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.