Skip to content

Boolean If Expression Identity

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: boolean-if-exp-identity

Section titled “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().