type-comparison
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”a = b = 1type(a) == type(b)type(a) != intint == type(a)type(a) is intisinstance(a, int)Configuration
Section titled “Configuration”python: lint: rules: type-comparison: warn # off, warn (default), errorSuppress one line with sudsy-disable-next-line type-comparison 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 | E721 |
full |