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
This commit is contained in:
lzyeval
2011-12-31 12:23:56 +08:00
parent d964a89f63
commit 47705d9f3b
5 changed files with 16 additions and 17 deletions

View File

@@ -1605,7 +1605,7 @@ class VsaDriveTypeCommands(object):
if name is not None: if name is not None:
search_opts['extra_specs']['name'] = name search_opts['extra_specs']['name'] = name
if all == False: if not all:
search_opts['extra_specs']['visible'] = '1' search_opts['extra_specs']['visible'] = '1'
drives = volume_types.get_all_types(self.context, drives = volume_types.get_all_types(self.context,
@@ -1973,7 +1973,7 @@ class StorageManagerCommands(object):
ctxt = context.get_admin_context() ctxt = context.get_admin_context()
try: try:
if flavor == None: if flavor is None:
flavors = db.sm_flavor_get_all(ctxt) flavors = db.sm_flavor_get_all(ctxt)
else: else:
flavors = db.sm_flavor_get(ctxt, flavor) flavors = db.sm_flavor_get(ctxt, flavor)
@@ -2015,7 +2015,7 @@ class StorageManagerCommands(object):
ctxt = context.get_admin_context() ctxt = context.get_admin_context()
try: try:
if backend_conf_id == None: if backend_conf_id is None:
backends = db.sm_backend_conf_get_all(ctxt) backends = db.sm_backend_conf_get_all(ctxt)
else: else:
backends = db.sm_backend_conf_get(ctxt, backend_conf_id) backends = db.sm_backend_conf_get(ctxt, backend_conf_id)
@@ -2075,7 +2075,7 @@ class StorageManagerCommands(object):
print '(WARNING: Creating will destroy all data on backend!!!)' print '(WARNING: Creating will destroy all data on backend!!!)'
c = raw_input('Proceed? (y/n) ') c = raw_input('Proceed? (y/n) ')
if c == 'y' or c == 'Y': if c == 'y' or c == 'Y':
if flavor_label == None: if flavor_label is None:
print "error: backend needs to be associated with flavor" print "error: backend needs to be associated with flavor"
sys.exit(2) sys.exit(2)

View File

@@ -821,7 +821,7 @@ class ConfigOpts(object):
:return: False if the opt was already register, True otherwise :return: False if the opt was already register, True otherwise
:raises: DuplicateOptError, ArgsAlreadyParsedError :raises: DuplicateOptError, ArgsAlreadyParsedError
""" """
if self._args != None: if self._args is not None:
raise ArgsAlreadyParsedError("cannot register CLI option") raise ArgsAlreadyParsedError("cannot register CLI option")
if not self.register_opt(opt, group): if not self.register_opt(opt, group):

View File

@@ -130,8 +130,7 @@ class VsaScheduler(simple.SimpleScheduler):
return filtered_hosts return filtered_hosts
def _allowed_to_use_host(self, host, selected_hosts, unique): def _allowed_to_use_host(self, host, selected_hosts, unique):
if unique == False or \ if not unique or host not in [item[0] for item in selected_hosts]:
host not in [item[0] for item in selected_hosts]:
return True return True
else: else:
return False return False

View File

@@ -236,11 +236,11 @@ class DistributedSchedulerTestCase(test.TestCase):
for weighted_host in weighted_hosts: for weighted_host in weighted_hosts:
# We set this up so remote hosts have even weights ... # We set this up so remote hosts have even weights ...
if int(weighted_host.weight) % 2 == 0: if int(weighted_host.weight) % 2 == 0:
self.assertTrue(weighted_host.zone != None) self.assertTrue(weighted_host.zone is not None)
self.assertTrue(weighted_host.host == None) self.assertTrue(weighted_host.host is None)
else: else:
self.assertTrue(weighted_host.host != None) self.assertTrue(weighted_host.host is not None)
self.assertTrue(weighted_host.zone == None) self.assertTrue(weighted_host.zone is None)
def test_schedule_local_zone(self): def test_schedule_local_zone(self):
"""Test to make sure _schedule makes no call out to zones if """Test to make sure _schedule makes no call out to zones if
@@ -270,8 +270,8 @@ class DistributedSchedulerTestCase(test.TestCase):
self.assertEquals(len(weighted_hosts), 10) self.assertEquals(len(weighted_hosts), 10)
for weighted_host in weighted_hosts: for weighted_host in weighted_hosts:
# There should be no remote hosts # There should be no remote hosts
self.assertTrue(weighted_host.host != None) self.assertTrue(weighted_host.host is not None)
self.assertTrue(weighted_host.zone == None) self.assertTrue(weighted_host.zone is None)
def test_decrypt_blob(self): def test_decrypt_blob(self):
"""Test that the decrypt method works.""" """Test that the decrypt method works."""

View File

@@ -68,10 +68,10 @@ class API(base.Base):
super(API, self).__init__(**kwargs) super(API, self).__init__(**kwargs)
def _check_volume_type_correctness(self, vol_type): def _check_volume_type_correctness(self, vol_type):
if vol_type.get('extra_specs') == None or\ if vol_type.get('extra_specs') is None or\
vol_type['extra_specs'].get('type') != 'vsa_drive' or\ vol_type['extra_specs'].get('type') != 'vsa_drive' or\
vol_type['extra_specs'].get('drive_type') == None or\ vol_type['extra_specs'].get('drive_type') is None or\
vol_type['extra_specs'].get('drive_size') == None: vol_type['extra_specs'].get('drive_size') is None:
raise exception.ApiError(_("Invalid drive type %s") raise exception.ApiError(_("Invalid drive type %s")
% vol_type['name']) % vol_type['name'])
@@ -162,7 +162,7 @@ class API(base.Base):
if storage is None: if storage is None:
storage = [] storage = []
if shared is None or shared == 'False' or shared == False: if not shared or shared == 'False':
shared = False shared = False
else: else:
shared = True shared = True