type
should be on the left side of the comparision operator288 def decorator(temp_cls: type) -> ReopenedType:
289 if temp_cls.__bases__ != (object,):
290 raise TypeError("Reopened class cannot add base classes")
291 if temp_cls.__class__ is not type:292 raise TypeError("Reopened class cannot add a metaclass")
293 if {
294 '__slots__',
Description
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')