Skip to content

none-comparison

Pythonsuspiciousno fixdefault: warn

Reports a comparison of a value to None with == or !=.

None is a single object, and is and is not test for it. == calls __eq__ of the other operand, which a class can define to return true for None (NumPy arrays compare element by element and return an array).

To fix, write x is None or x is not None.

Reported
x = 1
x == None
x != None
None == x
None != x
x is None
x == 1
python:
lint:
rules:
none-comparison: warn # off, warn (default), error

Suppress one line with sudsy-disable-next-line none-comparison 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 E711 full