Skip to content

Boolean If Expression Identity

Sourcery refactoring id: boolean-if-exp-identity


Simplifies boolean if expressions by removing unnecessary explicit references to True or False states


some_var = True if some_boolean_expression else False


some_var = some_boolean_expression


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().