Boolean If Expression Identity

Python pattern

When a boolean expression is used in an if-else to get a boolean value, use the boolean value directly.


Apply with the Grit CLI
grit apply bool_in_expr_ident

Boolean if expression identity

BEFORE
some_var = True if some_boolean_expression else False
some_var = False if some_boolean_expression else True

some_var = 1 if some_boolean_expression else 0
AFTER
some_var = bool(some_boolean_expression)
some_var = not bool(some_boolean_expression)

some_var = 1 if some_boolean_expression else 0