-
Notifications
You must be signed in to change notification settings - Fork 749
Closed
Description
According to PEP8,
- Object type comparisons should always use isinstance() instead
of comparing types directly.
Yes: if isinstance(obj, int):
No: if type(obj) is type(1):
When checking if an object is a string, keep in mind that it might be a
unicode string too! In Python 2.3, str and unicode have a common base
class, basestring, so you can do:
if isinstance(obj, basestring):
People, including me, tend to import the types module and do something like "type(XXX) is types.IntType".
Comparing types directly should trigger an error.
Metadata
Metadata
Assignees
Labels
No labels