Consider merging these isinstance calls to isinstance(baz, (float, int))
117 or isinstance(object, str)) and isinstance(other_obj, float)
118 and isinstance(foo, str)
119 or (isinstance(bar, float) or isinstance(bar, str)) and
120 (isinstance(baz, float) or isinstance(baz, int))):121 pass
122
123
Consider merging these isinstance calls to isinstance(bar, (float, str))
116 (isinstance(object, int) or isinstance(object, float)
117 or isinstance(object, str)) and isinstance(other_obj, float)
118 and isinstance(foo, str)
119 or (isinstance(bar, float) or isinstance(bar, str)) and120 (isinstance(baz, float) or isinstance(baz, int))):
121 pass
122
Consider merging these isinstance calls to isinstance(object, (float, int, str))
113
114def bad_isinstance(initial_condition, object, other_obj, foo, bar, baz):
115 if (initial_condition and
116 (isinstance(object, int) or isinstance(object, float)117 or isinstance(object, str)) and isinstance(other_obj, float)
118 and isinstance(foo, str)
119 or (isinstance(bar, float) or isinstance(bar, str)) and
Description
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')