DeepSource has joined Harness. Learn more
Python logoPython/
PTC-W0024

Bad `type` operand placementPTC-W0024

Minor severityMinor
Style categoryStyle

The type() call shall be placed on the left side of the comparison when checking the type of one object against another type. This affects readability.

Not preferred

x = 42
if int is type(x):
    print('This is an integer')

Preferred

x = 42
if type(x) is int:
    print('This is an integer')

Or even better, use isinstance:

x = 42
if isinstance(x, int):
    print('This is an integer')