Python

Python

Made by DeepSource

Consider merging isinstance calls PYL-R1701

Anti-pattern
Major
Autofix

You can pass a tuple of types you want to check as the second argument to isinstance. If the object matches with any of the types, it will return True else False.

It is therefore recommended to merge multiple consecutive isinstance calls into one. It is clearer and improves readability.

# Instead of
if isinstance(i, int) or isinstance(i, float):
    print('A number')

# Do this
if isinstance(i, (int, float)):
    print('A number')