PEP8 type comparison

Bug #910295 reported by Zhongyue Luo
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Wishlist
Zhongyue Luo

Bug Description

According to PEP8,

Programming Recommendations
    - Comparisons to singletons like None should always be done with
      'is' or 'is not', never the equality operators.

    - Don't compare boolean values to True or False using ==
        Yes: if greeting:
        No: if greeting == True:
        Worse: if greeting is True:

Therefore, all comparisons of value XXX to None
should be done by 'XXX is None' or 'XXX is not None'.

All comparison of value XXX to True or False
should be done by 'if XXX' or 'if not XXX'

The "== None", "== True", "== False", and "!= None" in sqlalchemy's
where(), or_(), filter(), and_(), and select() functions should not be changed.

Zhongyue Luo (zyluo)
Changed in nova:
assignee: nobody → LZY (lzyeval)
Zhongyue Luo (zyluo)
summary: - PEP8 "None" type comparison
+ PEP8 type comparison
description: updated
Revision history for this message
Zhongyue Luo (zyluo) wrote :

Comparisons in sqlalchemy filter's should not be changed this way.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/2712

Changed in nova:
status: New → In Progress
Zhongyue Luo (zyluo)
description: updated
description: updated
Brian Waldon (bcwaldon)
Changed in nova:
importance: Undecided → Wishlist
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/2712
Committed: http://github.com/openstack/nova/commit/88ccade9d5700db881f2ffc53e4a48a76e92c2db
Submitter: Jenkins
Branch: master

commit 88ccade9d5700db881f2ffc53e4a48a76e92c2db
Author: lzyeval <email address hidden>
Date: Sat Dec 31 12:23:56 2011 +0800

    PEP8 type comparison cleanup

    Fixes bug #910295

    The None, True, and False values are singletons.

    All variable *comparisons* to singletons should use 'is' or 'is not'.
    All variable *evaluations* to boolean should use 'if' or 'if not'.

    "== None", "== True", "== False", and "!= None" comparisons in sqlalchemy's
    where(), or_(), filter(), and_(), and select() functions should not be changed.

    Incorrect comparisons or evaluations in comments were not changed.

    Change-Id: I087f0883bf115b5fe714ccfda86a794b9b2a87f7

Changed in nova:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in nova:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.