Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deny direct variable type comparison #47

Closed
zyluo opened this issue Jan 2, 2012 · 2 comments
Closed

Deny direct variable type comparison #47

zyluo opened this issue Jan 2, 2012 · 2 comments

Comments

@zyluo
Copy link
Contributor

zyluo commented Jan 2, 2012

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.

@jendrikseipp
Copy link

+1

@florentx
Copy link
Contributor

Done in trunk.
However I worry a little we have a risk to trigger false positives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants