Boolean If Expression Identity¶
Sourcery refactoring id: boolean-if-exp-identity
¶
Description:¶
Simplifies boolean if expressions by removing unnecessary explicit references to
True
or False
states
Before:¶
some_var = True if some_boolean_expression else False
After:¶
some_var = some_boolean_expression
Explanation:¶
Rather than using an if-expression to evaluate a boolean, you can just use it directly. This is shorter and clearer - if expressions of this form take a while to mentally parse.
Where Sourcery cannot determine if the expression is a boolean it will wrap it
in a call tobool()
.