Removes explicit looping over dict .keys() method
Looping over the .keys() method of a dictionary is an anti-pattern. In fact, the method is actually creating a new list which is redundant and unnecessary. Looping over a dictionary implicitly loops over its keys. Change-Id: I937d3f060bf95bb86e50fcb5dec8def524f6208e
This commit is contained in:
parent
20d880abec
commit
a72f2c6fb7
@ -349,7 +349,7 @@ class BaseDataProcessingTest(tempest.test.BaseTestCase):
|
||||
return None
|
||||
|
||||
for plugin in CONF.data_processing_feature_enabled.plugins:
|
||||
if plugin in DEFAULT_TEMPLATES.keys():
|
||||
if plugin in DEFAULT_TEMPLATES:
|
||||
break
|
||||
else:
|
||||
plugin = ''
|
||||
|
@ -45,7 +45,7 @@ class TestSoftwareConfig(base.BaseOrchestrationTest):
|
||||
|
||||
def _validate_config(self, configuration, api_config):
|
||||
# Assert all expected keys are present with matching data
|
||||
for k in configuration.keys():
|
||||
for k in configuration:
|
||||
self.assertEqual(configuration[k],
|
||||
api_config['software_config'][k])
|
||||
|
||||
|
@ -94,7 +94,7 @@ class TestResources(object):
|
||||
self.router)
|
||||
|
||||
def set_resources(self, **kwargs):
|
||||
for key in kwargs.keys():
|
||||
for key in kwargs:
|
||||
if hasattr(self, key):
|
||||
setattr(self, key, kwargs[key])
|
||||
|
||||
|
@ -665,7 +665,7 @@ class Credentials(object):
|
||||
msg = ('Cannot have conflicting values for %s and %s' %
|
||||
(key1, key2))
|
||||
raise exceptions.InvalidCredentials(msg)
|
||||
for key in attr.keys():
|
||||
for key in attr:
|
||||
if key in self.ATTRIBUTES:
|
||||
setattr(self, key, attr[key])
|
||||
else:
|
||||
|
@ -103,7 +103,7 @@ def find_skips_in_file(path):
|
||||
|
||||
def get_results(result_dict):
|
||||
results = []
|
||||
for bug_no in result_dict.keys():
|
||||
for bug_no in result_dict:
|
||||
for method in result_dict[bug_no]:
|
||||
results.append((method, bug_no))
|
||||
return results
|
||||
|
@ -74,7 +74,7 @@ class TestAggregatesBasicOps(manager.ScenarioTest):
|
||||
self.assertEqual(aggregate_name, aggregate['name'])
|
||||
self.assertEqual(azone, aggregate['availability_zone'])
|
||||
self.assertEqual(hosts, aggregate['hosts'])
|
||||
for meta_key in metadata.keys():
|
||||
for meta_key in metadata:
|
||||
self.assertIn(meta_key, aggregate['metadata'])
|
||||
self.assertEqual(metadata[meta_key],
|
||||
aggregate['metadata'][meta_key])
|
||||
|
@ -31,5 +31,5 @@ class FakeAuthProvider(object):
|
||||
class FakeCredentials(object):
|
||||
|
||||
def __init__(self, creds_dict):
|
||||
for key in creds_dict.keys():
|
||||
for key in creds_dict:
|
||||
setattr(self, key, creds_dict[key])
|
||||
|
@ -99,7 +99,7 @@ class KeystoneV2CredentialsTests(CredentialsTests):
|
||||
|
||||
def _test_is_not_valid(self, ignore_key):
|
||||
creds = self._get_credentials()
|
||||
for attr in self.attributes.keys():
|
||||
for attr in self.attributes:
|
||||
if attr == ignore_key:
|
||||
continue
|
||||
temp_attr = getattr(creds, attr)
|
||||
|
@ -77,8 +77,8 @@ class TestServiceClients(base.TestCase):
|
||||
uri = 'fake_uri'
|
||||
_manager = service_clients.ServiceClients(creds, identity_uri=uri,
|
||||
client_parameters=params)
|
||||
self.assertIn('fake_service1', _manager.parameters.keys())
|
||||
for _key in expeted_params.keys():
|
||||
self.assertIn('fake_service1', _manager.parameters)
|
||||
for _key in expeted_params:
|
||||
self.assertIn(_key, _manager.parameters['fake_service1'].keys())
|
||||
self.assertEqual(expeted_params[_key],
|
||||
_manager.parameters['fake_service1'].get(_key))
|
||||
|
@ -95,7 +95,7 @@ def find_skips_in_file(path):
|
||||
|
||||
def get_results(result_dict):
|
||||
results = []
|
||||
for bug_no in result_dict.keys():
|
||||
for bug_no in result_dict:
|
||||
for method in result_dict[bug_no]:
|
||||
results.append((method, bug_no))
|
||||
return results
|
||||
|
Loading…
Reference in New Issue
Block a user