Skip to content

type-comparison

Pythonsuspiciousno fixdefault: warn

Reports a comparison with == or != where one side is type(x) or a builtin class such as int. A name that shadows the builtin is not reported.

type(x) == int is false for a subclass (a bool is not an int by this test, and an enum with int as a base is not either), while isinstance(x, int) says what is usually meant. When the exact type is meant, is states it.

To fix, use isinstance(x, int), or type(x) is int for an exact match.

Reported
a = b = 1
type(a) == type(b)
type(a) != int
int == type(a)
type(a) is int
isinstance(a, int)
python:
lint:
rules:
type-comparison: warn # off, warn (default), error

Suppress one line with sudsy-disable-next-line type-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 E721 full