Skip to content

repeated-isinstance-calls (PLR1701)#

Derived from the Pylint linter.

Fix is always available.

What it does#

Checks for repeated isinstance calls on the same object.

Why is this bad?#

Repeated isinstance calls on the same object can be merged into a single call.

Example#

def is_number(x):
    return isinstance(x, int) or isinstance(x, float) or isinstance(x, complex)

Use instead:

def is_number(x):
    return isinstance(x, (int, float, complex))

Or, for Python 3.10 and later:

def is_number(x):
    return isinstance(x, int | float | complex)

Options#

References#