Skip to content

Files

Latest commit

 

History

History
27 lines (17 loc) · 571 Bytes

File metadata and controls

27 lines (17 loc) · 571 Bytes

Pattern: Missing use of isinstance()

Issue: -

Description

A object should be be compared to a type by using isinstance. This is because isinstance can handle subclasses as well.

Example of incorrect code:

The below example will not handle a potential future case where user is a subclass or User.

if type(user) == User:
    print(user.name)

Example of correct code:

if isinstance(user, User):
    print(user.name)

Further Reading