needless-bool
What it does
Section titled “What it does”Reports an if that returns True or False and is followed, directly or in an else, by a return of the opposite boolean.
Why it matters
Section titled “Why it matters”The if only turns a condition into the bool it already is. The condition itself, or bool(...) of it, is the value, and the four lines hide that.
To fix, return the condition.
Example
Section titled “Example”...
def f(x): if x: return True return False
...Configuration
Section titled “Configuration”python: lint: rules: needless-bool: warn # off (default), warn, errorEnabled by the presets: python/ruff.
Suppress one line with sudsy-disable-next-line needless-bool 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 | SIM103 |
full |