Skip to content

Remove Redundant Boolean

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: remove-redundant-boolean

Section titled “Sourcery refactoring id: remove-redundant-boolean”

Removes redundant booleans from tests.

hat_prices = []
while True and hat in hats:
hat_prices.append(hat.price)
hats.remove(hat)
assert len(hat_prices) > 10 and False
while hat in hats:
hat_prices.append(hat.price)
hats.remove(hat)
assert False

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