From: Christian Berendt Date: Fri, 1 Aug 2014 11:10:20 +0000 (+0200) Subject: Enable checks for E711, E712 and E713 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1be1da1020281a83d6285173a6d6078ffe979194;p=openstack-build%2Fcinder-build.git Enable checks for E711, E712 and E713 * E711 comparison to None should be 'if cond is None:' * E712 comparison to True should be 'if cond is True:' or 'if cond:' * E713 test for membership should be 'not in' Change-Id: I1481209a85fa6db0343d0111e2b19d9fab4538a7 --- diff --git a/bin/cinder-rtstool b/bin/cinder-rtstool index fd61d2635..a95d47f7e 100755 --- a/bin/cinder-rtstool +++ b/bin/cinder-rtstool @@ -95,7 +95,7 @@ def add_initiator(target_iqn, initiator_iqn, userid, password): if t.dump()['wwn'] == target_iqn: target = t break - if target == None: + if target is None: raise RtstoolError(_('Could not find target %s') % target_iqn) tpg = target.tpgs.next() # get the first one diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 4f3568ffe..062b7b5b6 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -1159,7 +1159,7 @@ def volume_get_all(context, marker, limit, sort_key, sort_dir, query = _generate_paginate_query(context, session, marker, limit, sort_key, sort_dir, filters) # No volumes would match, return empty list - if query == None: + if query is None: return [] return query.all() @@ -1197,7 +1197,7 @@ def volume_get_all_by_project(context, project_id, marker, limit, sort_key, query = _generate_paginate_query(context, session, marker, limit, sort_key, sort_dir, filters) # No volumes would match, return empty list - if query == None: + if query is None: return [] return query.all() @@ -1230,11 +1230,11 @@ def _generate_paginate_query(context, session, marker, limit, sort_key, # 'no_migration_targets' is unique, must be either NULL or # not start with 'target:' if ('no_migration_targets' in filters and - filters['no_migration_targets'] == True): + filters['no_migration_targets'] is True): filters.pop('no_migration_targets') try: column_attr = getattr(models.Volume, 'migration_status') - conditions = [column_attr == None, + conditions = [column_attr == None, # noqa column_attr.op('NOT LIKE')('target:%')] query = query.filter(or_(*conditions)) except AttributeError: @@ -1630,7 +1630,7 @@ def snapshot_get_active_by_window(context, begin, end=None, project_id=None): """Return snapshots that were active during window.""" query = model_query(context, models.Snapshot, read_deleted="yes") - query = query.filter(or_(models.Snapshot.deleted_at == None, + query = query.filter(or_(models.Snapshot.deleted_at == None, # noqa models.Snapshot.deleted_at > begin)) query = query.options(joinedload(models.Snapshot.volume)) if end: @@ -1952,7 +1952,7 @@ def volume_get_active_by_window(context, project_id=None): """Return volumes that were active during window.""" query = model_query(context, models.Volume, read_deleted="yes") - query = query.filter(or_(models.Volume.deleted_at == None, + query = query.filter(or_(models.Volume.deleted_at == None, # noqa models.Volume.deleted_at > begin)) if end: query = query.filter(models.Volume.created_at < end) diff --git a/cinder/tests/api/fakes.py b/cinder/tests/api/fakes.py index 4f3bfd7a0..6fec0c86a 100644 --- a/cinder/tests/api/fakes.py +++ b/cinder/tests/api/fakes.py @@ -120,7 +120,7 @@ class HTTPRequest(webob.Request): @classmethod def blank(cls, *args, **kwargs): - if args != None: + if args is not None: if args[0].find('v1') == 0: kwargs['base_url'] = 'http://localhost/v1' else: diff --git a/cinder/tests/api/v2/test_volumes.py b/cinder/tests/api/v2/test_volumes.py index 3e42e2390..2103ed1af 100644 --- a/cinder/tests/api/v2/test_volumes.py +++ b/cinder/tests/api/v2/test_volumes.py @@ -913,7 +913,7 @@ class VolumeApiTest(test.TestCase): viewable_admin_meta=False): vols = [stubs.stub_volume(i) for i in xrange(CONF.osapi_max_limit)] - if limit == None or limit >= len(vols): + if limit is None or limit >= len(vols): return vols return vols[:limit] self.stubs.Set(db, 'volume_get_all', stub_volume_get_all) @@ -932,7 +932,7 @@ class VolumeApiTest(test.TestCase): viewable_admin_meta=False): vols = [stubs.stub_volume(i) for i in xrange(100)] - if limit == None or limit >= len(vols): + if limit is None or limit >= len(vols): return vols return vols[:limit] self.stubs.Set(db, 'volume_get_all', stub_volume_get_all2) @@ -950,7 +950,7 @@ class VolumeApiTest(test.TestCase): viewable_admin_meta=False): vols = [stubs.stub_volume(i) for i in xrange(CONF.osapi_max_limit + 100)] - if limit == None or limit >= len(vols): + if limit is None or limit >= len(vols): return vols return vols[:limit] self.stubs.Set(db, 'volume_get_all', stub_volume_get_all3) diff --git a/cinder/tests/keymgr/test_key.py b/cinder/tests/keymgr/test_key.py index d37688ef2..d5f4ed172 100644 --- a/cinder/tests/keymgr/test_key.py +++ b/cinder/tests/keymgr/test_key.py @@ -57,11 +57,11 @@ class SymmetricKeyTestCase(KeyTestCase): def test___eq__(self): self.assertTrue(self.key == self.key) - self.assertFalse(self.key == None) + self.assertFalse(self.key is None) self.assertFalse(None == self.key) def test___ne__(self): self.assertFalse(self.key != self.key) - self.assertTrue(self.key != None) + self.assertTrue(self.key is not None) self.assertTrue(None != self.key) diff --git a/cinder/tests/test_hds_iscsi.py b/cinder/tests/test_hds_iscsi.py index 6a673ef2d..48bcaffac 100644 --- a/cinder/tests/test_hds_iscsi.py +++ b/cinder/tests/test_hds_iscsi.py @@ -310,7 +310,7 @@ class HNASiSCSIDriverTest(test.TestCase): self.driver.delete_volume(vol) # should not be deletable twice prov_loc = self.backend.getVolumebyProvider(vol['provider_location']) - self.assertTrue(prov_loc == None) + self.assertTrue(prov_loc is None) def test_extend_volume(self): vol = self._create_volume() @@ -355,7 +355,7 @@ class HNASiSCSIDriverTest(test.TestCase): lun = svol['provider_location'] m_id_to_vol.return_value = svol self.driver.delete_snapshot(svol) - self.assertTrue(self.backend.getVolumebyProvider(lun) == None) + self.assertTrue(self.backend.getVolumebyProvider(lun) is None) def test_create_volume_from_snapshot(self): svol = self._create_volume() diff --git a/cinder/utils.py b/cinder/utils.py index 0807e9464..3050e1293 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -132,7 +132,7 @@ def check_exclusive_options(**kwargs): def execute(*cmd, **kwargs): """Convenience wrapper around oslo's execute() method.""" - if 'run_as_root' in kwargs and not 'root_helper' in kwargs: + if 'run_as_root' in kwargs and 'root_helper' not in kwargs: kwargs['root_helper'] = get_root_helper() return processutils.execute(*cmd, **kwargs) diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 89355772e..a98df1527 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -292,7 +292,7 @@ class API(base.Base): def get_all(self, context, marker=None, limit=None, sort_key='created_at', sort_dir='desc', filters=None, viewable_admin_meta=False): check_policy(context, 'get_all') - if filters == None: + if filters is None: filters = {} try: diff --git a/cinder/volume/drivers/emc/emc_smis_common.py b/cinder/volume/drivers/emc/emc_smis_common.py index f3ff96a06..e86af44b4 100644 --- a/cinder/volume/drivers/emc/emc_smis_common.py +++ b/cinder/volume/drivers/emc/emc_smis_common.py @@ -1047,7 +1047,7 @@ class EMCSMISCommon(): def _get_storage_type_conffile(self, filename=None): """Get the storage type from the config file.""" - if filename == None: + if filename is None: filename = self.configuration.cinder_emc_config_file file = open(filename, 'r') diff --git a/cinder/volume/drivers/eqlx.py b/cinder/volume/drivers/eqlx.py index 6eec44de0..685b84f1e 100644 --- a/cinder/volume/drivers/eqlx.py +++ b/cinder/volume/drivers/eqlx.py @@ -448,7 +448,7 @@ class DellEQLSanISCSIDriver(SanISCSIDriver): out = self._eql_execute('volume', 'select', volume['name'], 'access', 'show') connection_id = self._parse_connection(connector, out) - if connection_id != None: + if connection_id is not None: self._eql_execute('volume', 'select', volume['name'], 'access', 'delete', connection_id) except Exception: diff --git a/cinder/volume/drivers/netapp/iscsi.py b/cinder/volume/drivers/netapp/iscsi.py index 630b87b8d..30963e1e9 100644 --- a/cinder/volume/drivers/netapp/iscsi.py +++ b/cinder/volume/drivers/netapp/iscsi.py @@ -1527,7 +1527,7 @@ class NetAppDirect7modeISCSIDriver(NetAppDirectISCSIDriver): vols = self._get_filer_volumes() for vol in vols: volume = vol.get_child_content('name') - if self.volume_list and not volume in self.volume_list: + if self.volume_list and volume not in self.volume_list: continue state = vol.get_child_content('state') inconsistent = vol.get_child_content('is-inconsistent') diff --git a/tox.ini b/tox.ini index 87feb47c1..51416a3cd 100644 --- a/tox.ini +++ b/tox.ini @@ -72,7 +72,7 @@ commands = {posargs} # F841,H302,H305,H307,H405 -ignore = E251,E265,E711,E712,E713,F402,F841,H104,H302,H305,H307,H402,H405,H803,H904 +ignore = E251,E265,F402,F841,H104,H302,H305,H307,H402,H405,H803,H904 builtins = _ exclude = .git,.venv,.tox,dist,tools,doc,common,*egg,build