summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhongyue Luo <zhongyue.nah@intel.com>2013-02-04 10:07:08 +0800
committerZhongyue Luo <zhongyue.nah@intel.com>2013-02-04 11:12:25 +0800
commit896295844a527327b0cd86b10244f403b31f155f (patch)
treeac6c8c32db1115885fe01fa5af775a6d73480a33
parentee955d272ab4eef2e8371f2e460454058ce7e46c (diff)
downloadnova-896295844a527327b0cd86b10244f403b31f155f.tar.gz
nova-896295844a527327b0cd86b10244f403b31f155f.tar.xz
nova-896295844a527327b0cd86b10244f403b31f155f.zip
Update HACKING.rst per recent changes
Added "is not" usage with examples * https://review.openstack.org/#/c/20865/ Fixed "not in" usage description * https://review.openstack.org/#/c/20875/ Fixed some "not X in Y" corner cases. Change-Id: I7534ef73e6fd525fd8f4bee594a4b37524699c08
-rw-r--r--HACKING.rst13
-rw-r--r--nova/api/openstack/compute/servers.py2
-rw-r--r--nova/scheduler/filters/json_filter.py2
3 files changed, 12 insertions, 5 deletions
diff --git a/HACKING.rst b/HACKING.rst
index 54e3b3275..213495832 100644
--- a/HACKING.rst
+++ b/HACKING.rst
@@ -28,16 +28,23 @@ General
mylist = Foo().list() # OKAY, does not shadow built-in
+- Use the "is not" operator when testing for unequal identities. Example::
-- Use the "not in" operator for collection membership evaluation. Example::
+ if not X is Y: # BAD, intended behavior is ambiguous
+ pass
+
+ if X is not Y: # OKAY, intuitive
+ pass
+
+- Use the "not in" operator for evaluating membership in a collection. Example::
- if not X in Y: # BAD, hard to understand
+ if not X in Y: # BAD, intended behavior is ambiguous
pass
if X not in Y: # OKAY, intuitive
pass
- if not (X in Y or X is Z): # OKAY, still better than all those 'not's
+ if not (X in Y or X in Z): # OKAY, still better than all those 'not's
pass
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index 88a52001c..bf3f4cacc 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -1172,7 +1172,7 @@ class Controller(wsgi.Controller):
def _action_change_password(self, req, id, body):
context = req.environ['nova.context']
if (not 'changePassword' in body
- or not 'adminPass' in body['changePassword']):
+ or 'adminPass' not in body['changePassword']):
msg = _("No adminPass was specified")
raise exc.HTTPBadRequest(explanation=msg)
password = body['changePassword']['adminPass']
diff --git a/nova/scheduler/filters/json_filter.py b/nova/scheduler/filters/json_filter.py
index 2d070ea8e..f77d6dad3 100644
--- a/nova/scheduler/filters/json_filter.py
+++ b/nova/scheduler/filters/json_filter.py
@@ -32,7 +32,7 @@ class JsonFilter(filters.BaseHostFilter):
if len(args) < 2:
return False
if op is operator.contains:
- bad = not args[0] in args[1:]
+ bad = args[0] not in args[1:]
else:
bad = [arg for arg in args[1:]
if not op(args[0], arg)]