if-expr-with-twisted-arms
What it does
Section titled “What it does”Reports a conditional expression of the form b if not a else a.
Why it matters
Section titled “Why it matters”b if not a else a gives a when a is true and b otherwise, which is a or b. The negation only puts the arms in the opposite order, and a condition that is not negated is easier to read.
To fix, write a or b, or swap the arms and drop the not.
Example
Section titled “Example”...x = 1 if a else 1x = b if not a else ax = b if a else a...x = 1 if a else 1x = b if not a else ax = b if a else aConfiguration
Section titled “Configuration”python: lint: rules: if-expr-with-twisted-arms: warn # off (default), warn, errorSuppress one line with sudsy-disable-next-line if-expr-with-twisted-arms in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| ruff | SIM212 |
full |