Pattern: Missing use of isinstance()
Issue: -
A object should be be compared to a type by using isinstance
. This is because isinstance
can handle subclasses as well.
The below example will not handle a potential future case where user
is a subclass or User
.
if type(user) == User:
print(user.name)
if isinstance(user, User):
print(user.name)