Skip to content

if-expr-with-false-true

Pythonstyleno fixdefault: offpython/ruff

Reports a conditional expression whose arms are False and True: False if a else True.

The expression is not a, written the long way round.

To fix, write not a.

Reported
...
x = not a == b == c
...
x = False if a else True
x = 1 if a else 1
...
x = b if a else a
After the fix
...
x = not a == b == c
...
x = False if a else True
x = 1 if a else 1
...
x = b if a else a
python:
lint:
rules:
if-expr-with-false-true: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line if-expr-with-false-true in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff SIM211 full