if-else-block-instead-of-if-exp (SIM108)#
Derived from the flake8-simplify linter.
Fix is sometimes available.
What it does#
Check for if-else-blocks that can be replaced with a ternary operator.
Moreover, in preview, check if these ternary expressions can be
further simplified to binary expressions.
Why is this bad?#
if-else-blocks that assign a value to a variable in both branches can
be expressed more concisely by using a ternary or binary operator.
Example#
Use instead:
Or, in preview:
Use instead: