Skip to content


Sourcery rule id: or-if-exp-identity


Replace if-expression with or


currency = input_currency if input_currency else DEFAULT_CURRENCY


currency = input_currency or DEFAULT_CURRENCY


Here we find ourselves setting a value if it evaluates to True, and otherwise using a default.

The 'After' case is a bit easier to read and avoids the duplication of input_currency.

It works because the left-hand side is evaluated first. If it evaluates to true then currency will be set to this and the right-hand side will not be evaluated. If it evaluates to false the right-hand side will be evaluated and currency will be set to DEFAULT_CURRENCY.