if-expr-with-true-false
What it does
Section titled “What it does”Reports a conditional expression whose arms are True and False: True if a else False.
Why it matters
Section titled “Why it matters”The expression is the truth of a. When a is already a comparison, it is that comparison.
To fix, write bool(a), or a itself if it is already a bool.
Example
Section titled “Example”...x = not a < bx = not a == b == c...x = True if a else False...x = 1 if a else 1......x = not a < bx = not a == b == c...x = True if a else False...x = 1 if a else 1...Configuration
Section titled “Configuration”python: lint: rules: if-expr-with-true-false: warn # off (default), warn, errorEnabled by the presets: python/ruff.
Suppress one line with sudsy-disable-next-line if-expr-with-true-false 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 | SIM210 |
full |