Skip to content

Remove Redundant Boolean

Sourcery refactoring id: remove-redundant-boolean

Description

Removes redundant booleans from tests.

Before

hat_prices = []
while True and hat in hats:
    hat_prices.append(hat.price)
    hats.remove(hat)


assert len(hat_prices) > 10 and False

After

while hat in hats:
    hat_prices.append(hat.price)
    hats.remove(hat)

assert False

Explanation

Boolean values like True or False in boolean operations like and or or may be redundant, and can be removed to simplify the code without affecting its functionality. This refactoring will often compose with other refactorings where boolean operations have been combined.

See also: remove-redundant-if

Back to top