Skip to content

type-comparison (E721)#

Derived from the pycodestyle linter.

What it does#

Checks for object type comparisons using == and other comparison operators.

Why is this bad?#

Unlike a direct type comparison, isinstance will also check if an object is an instance of a class or a subclass thereof.

Under preview mode, this rule also allows for direct type comparisons using is and is not, to check for exact type equality (while still forbidding comparisons using == and !=).


if type(obj) == type(1):

if type(obj) == int:

Use instead:

if isinstance(obj, int):