ruff
0c2b88f2 - [`flake8-simplify`] Further simplify to binary in preview for `if-else-block-instead-of-if-exp (SIM108)` (#12796)

Commit
1 year ago
[`flake8-simplify`] Further simplify to binary in preview for `if-else-block-instead-of-if-exp (SIM108)` (#12796) In most cases we should suggest a ternary operator, but there are three edge cases where a binary operator is more appropriate. Given an if-else block of the form ```python if test: target_var = body_value else: target_var = else_value ``` This PR updates the check for SIM108 to the following: - If `test == body_value` and preview enabled, suggest to replace with `target_var = test or else_value` - If `test == not body_value` and preview enabled, suggest to replace with `target_var = body_value and else_value` - If `not test == body_value` and preview enabled, suggest to replace with `target_var = body_value and else_value` - Otherwise, suggest to replace with `target_var = body_value if test else else_value` Closes #12189.
Author
Parents
Loading