Skip to content

double-negation

Pythonstylefix: unsafedefault: offpython/ruff

Reports not not x.

A double not turns a value into a bool, but the reader has to unwind two negations to see that. bool(x) says it, and in a condition the not not can be dropped.

To fix, write bool(x), or x where only the truth is needed.

Reported
...
x = not a < b
x = not a == b == c
x = not not a
...
x = 1 if a else 1
...
After the fix
...
x = not a < b
x = not a == b == c
x = a
...
x = 1 if a else 1
...
python:
lint:
rules:
double-negation: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line double-negation 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 SIM208 full