Fixes 'not in' operator usage

Change-Id: Id4c83e32f6dcb4f710c5a8d8b6f130038cf07648
This commit is contained in:
Zhongyue Luo 2013-01-31 14:58:50 +08:00
parent 31e481667d
commit b1764fdc83
19 changed files with 42 additions and 23 deletions

View File

@ -27,6 +27,25 @@ General
mylist = Foo().list() # OKAY, does not shadow built-in
- Use the "is not" operator when testing for unequal identities. 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, intended behavior is ambiguous
pass
if X not in Y: # OKAY, intuitive
pass
if not (X in Y or X in Z): # OKAY, still better than all those 'not's
pass
Imports
-------

View File

@ -98,7 +98,7 @@ class VolumeTypeExtraSpecsController(wsgi.Controller):
expl = _('Request body empty')
raise webob.exc.HTTPBadRequest(explanation=expl)
self._check_type(context, type_id)
if not id in body:
if id not in body:
expl = _('Request body and URI mismatch')
raise webob.exc.HTTPBadRequest(explanation=expl)
if len(body) > 1:

View File

@ -41,7 +41,7 @@ class APIMapper(routes.Mapper):
class ProjectMapper(APIMapper):
def resource(self, member_name, collection_name, **kwargs):
if not ('parent_resource' in kwargs):
if 'parent_resource' not in kwargs:
kwargs['path_prefix'] = '{project_id}/'
else:
parent_resource = kwargs['parent_resource']

View File

@ -89,7 +89,7 @@ class Request(webob.Request):
Does not do any body introspection, only checks header
"""
if not "Content-Type" in self.headers:
if "Content-Type" not in self.headers:
return None
allowed_types = SUPPORTED_CONTENT_TYPES

View File

@ -188,7 +188,7 @@ class SnapshotsController(wsgi.Controller):
if not body:
raise exc.HTTPUnprocessableEntity()
if not 'snapshot' in body:
if 'snapshot' not in body:
raise exc.HTTPUnprocessableEntity()
snapshot = body['snapshot']

View File

@ -378,7 +378,7 @@ class VolumeController(wsgi.Controller):
if not body:
raise exc.HTTPUnprocessableEntity()
if not 'volume' in body:
if 'volume' not in body:
raise exc.HTTPUnprocessableEntity()
volume = body['volume']

View File

@ -188,7 +188,7 @@ class SnapshotsController(wsgi.Controller):
if not body:
raise exc.HTTPUnprocessableEntity()
if not 'snapshot' in body:
if 'snapshot' not in body:
raise exc.HTTPUnprocessableEntity()
snapshot = body['snapshot']

View File

@ -302,7 +302,7 @@ class VolumeController(wsgi.Controller):
if not body:
raise exc.HTTPUnprocessableEntity()
if not 'volume' in body:
if 'volume' not in body:
raise exc.HTTPUnprocessableEntity()
volume = body['volume']

View File

@ -351,7 +351,7 @@ class WSGIService(object):
"""
fl = '%s_manager' % self.name
if not fl in FLAGS:
if fl not in FLAGS:
return None
manager_class_name = FLAGS.get(fl, None)

View File

@ -185,6 +185,6 @@ class FakeRateLimiter(object):
def get_fake_uuid(token=0):
if not token in FAKE_UUIDS:
if token not in FAKE_UUIDS:
FAKE_UUIDS[token] = str(uuid.uuid4())
return FAKE_UUIDS[token]

View File

@ -150,7 +150,7 @@ class TestOpenStackClient(object):
LOG.debug(_("%(relative_uri)s => code %(http_status)s") % locals())
if check_response_status:
if not http_status in check_response_status:
if http_status not in check_response_status:
if http_status == 404:
raise OpenStackApiNotFoundException(response=response)
elif http_status == 401:

View File

@ -51,7 +51,7 @@ def generate_new_element(items, prefix, numeric=False):
candidate = prefix + generate_random_numeric(8)
else:
candidate = prefix + generate_random_alphanumeric(8)
if not candidate in items:
if candidate not in items:
return candidate
LOG.debug("Random collision on %s" % candidate)

View File

@ -72,7 +72,7 @@ class VolumesTest(integrated_helpers._IntegratedTestBase):
self.assertEqual(volume_id, found_volume['id'])
if not found_volume['status'] in continue_states:
if found_volume['status'] not in continue_states:
break
time.sleep(1)

View File

@ -391,7 +391,7 @@ class StorwizeSVCManagementSimulator:
return self._errors["CMMVC5701E"]
vol_name = kwargs["obj"].strip('\'\"')
if not vol_name in self._volumes_list:
if vol_name not in self._volumes_list:
return self._errors["CMMVC5753E"]
if force == 0:
@ -661,10 +661,10 @@ class StorwizeSVCManagementSimulator:
return self._errors["CMMVC5707E"]
mapping_info["vol"] = kwargs["obj"].strip('\'\"')
if not mapping_info["vol"] in self._volumes_list:
if mapping_info["vol"] not in self._volumes_list:
return self._errors["CMMVC5753E"]
if not mapping_info["host"] in self._hosts_list:
if mapping_info["host"] not in self._hosts_list:
return self._errors["CMMVC5754E"]
if mapping_info["vol"] in self._mappings_list:
@ -689,7 +689,7 @@ class StorwizeSVCManagementSimulator:
return self._errors["CMMVC5701E"]
vol = kwargs["obj"].strip('\'\"')
if not vol in self._mappings_list:
if vol not in self._mappings_list:
return self._errors["CMMVC5753E"]
if self._mappings_list[vol]["host"] != host:
@ -729,13 +729,13 @@ class StorwizeSVCManagementSimulator:
if "source" not in kwargs:
return self._errors["CMMVC5707E"]
source = kwargs["source"].strip('\'\"')
if not source in self._volumes_list:
if source not in self._volumes_list:
return self._errors["CMMVC5754E"]
if "target" not in kwargs:
return self._errors["CMMVC5707E"]
target = kwargs["target"].strip('\'\"')
if not target in self._volumes_list:
if target not in self._volumes_list:
return self._errors["CMMVC5754E"]
if source == target:

View File

@ -164,7 +164,7 @@ class MockProxy(object):
l.append(val)
def _add_recorded_value(self, name, val):
if not name in self._recorded_values:
if name not in self._recorded_values:
self._recorded_values[name] = []
self._recorded_values[name].append(val)

View File

@ -70,7 +70,7 @@ class LVMVolumeDriver(driver.VolumeDriver):
out, err = self._execute('vgs', '--noheadings', '-o', 'name',
run_as_root=True)
volume_groups = out.split()
if not FLAGS.volume_group in volume_groups:
if FLAGS.volume_group not in volume_groups:
exception_message = (_("volume group %s doesn't exist")
% FLAGS.volume_group)
raise exception.VolumeBackendAPIException(data=exception_message)

View File

@ -1306,7 +1306,7 @@ class NetAppCmodeISCSIDriver(driver.ISCSIDriver):
def _get_lun_handle(self, name):
"""Get the details for a LUN from our cache table."""
if not name in self.lun_table:
if name not in self.lun_table:
LOG.warn(_("Could not find handle for LUN named %s") % name)
return None
return self.lun_table[name].handle

View File

@ -55,7 +55,7 @@ class RBDDriver(driver.VolumeDriver):
"""Returns an error if prerequisites aren't met"""
(stdout, stderr) = self._execute('rados', 'lspools')
pools = stdout.split("\n")
if not FLAGS.rbd_pool in pools:
if FLAGS.rbd_pool not in pools:
exception_message = (_("rbd has no pool %s") %
FLAGS.rbd_pool)
raise exception.VolumeBackendAPIException(data=exception_message)

View File

@ -37,7 +37,7 @@ class SheepdogDriver(driver.VolumeDriver):
# gives short output, but for compatibility reason we won't
# use it and just check if 'running' is in the output.
(out, err) = self._execute('collie', 'cluster', 'info')
if not 'running' in out.split():
if 'running' not in out.split():
exception_message = (_("Sheepdog is not working: %s") % out)
raise exception.VolumeBackendAPIException(
data=exception_message)