PEP8 horizon cleanup
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenStack Dashboard (Horizon) |
Fix Released
|
Undecided
|
Zhongyue Luo |
Bug Description
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'.
All Object type comparisons should use isinstance() instead of comparing types directly
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:
- 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):
Changed in horizon: | |
assignee: | nobody → LZY (lzyeval) |
summary: |
- PEP8 cleanup + PEP8 horizon cleanup |
Changed in horizon: | |
milestone: | none → essex-3 |
status: | Fix Committed → Fix Released |
Changed in horizon: | |
milestone: | essex-3 → 2012.1 |
Fix proposed to branch: master /review. openstack. org/2769
Review: https:/