Replace six.iteritems() with .items()

1.As mentioned in [1], we should avoid using
six.iteritems to achieve iterators. We can
use dict.items instead, as it will return
iterators in PY3 as well. And dict.items/keys
will more readable. 2.In py2, the performance
about list should be negligible, see the link [2].
[1] https://wiki.openstack.org/wiki/Python3
[2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html

Change-Id: If17002f8ce9ddb44109feca9bed9524299c404c4
This commit is contained in:
pawnesh.kumar 2017-03-30 15:33:33 +05:30
parent 9402320c72
commit 20ae6d4418
4 changed files with 9 additions and 11 deletions

View File

@ -14,7 +14,6 @@
from oslo_log import log as logging
from django.utils.translation import ugettext_lazy as _
import six
from horizon import exceptions
from horizon import tabs
@ -91,15 +90,15 @@ class LabelsTab(tabs.Tab):
_('Unable to retrieve plugin.'))
labels = []
for label, data in six.iteritems(plugin.plugin_labels):
for label, data in plugin.plugin_labels.items():
labels.append(
{'name': label,
'color': self._label_color(label),
'description': data.get('description', _("No description")),
'scope': _("Plugin"), 'status': data.get('status', False)})
for version, version_data in six.iteritems(plugin.version_labels):
for label, data in six.iteritems(version_data):
for version, version_data in plugin.version_labels.items():
for label, data in version_data.items():
labels.append(
{'name': label,
'color': self._label_color(label),

View File

@ -41,7 +41,7 @@ class UpdateLabelsAction(workflows.Action):
initial=plugin_name)
def _serialize_labels(self, prefix, prefix_trans, labels):
for name, label in six.iteritems(labels):
for name, label in labels.items():
if not label['mutable']:
continue
res_name_translated = "%s: %s" % (six.text_type(prefix_trans),
@ -65,7 +65,7 @@ class UpdatePluginStep(workflows.Step):
depends_on = ('plugin_name', )
def contribute(self, data, context):
for name, item in six.iteritems(data):
for name, item in data.items():
context[name] = item
return context
@ -84,7 +84,7 @@ class UpdatePlugin(workflows.Workflow):
def _get_update_values(self, context):
values = {'plugin_labels': {}, 'version_labels': {}}
for item, item_value in six.iteritems(context):
for item, item_value in context.items():
if not item.startswith('label_'):
continue
name = item.split('_')[1:]

View File

@ -14,7 +14,6 @@
import json
from django.utils.translation import ugettext_lazy as _
import six
from horizon import exceptions
from horizon import forms
@ -313,7 +312,7 @@ class JobConfigAction(workflows.Action):
def clean_edp_configs(self, configs):
edp_configs = {}
for key, value in six.iteritems(configs):
for key, value in configs.items():
if key.startswith(self.EDP_PREFIX):
edp_configs[key] = value
for rmkey in edp_configs.keys():

View File

@ -437,7 +437,7 @@ def get_enabled_versions(plugin):
lbs = plugin.version_labels
versions = []
for version, data in six.iteritems(lbs):
for version, data in lbs.items():
if data.get('enabled', {'status': True}).get('status', True):
versions.append(version)
@ -449,7 +449,7 @@ def get_enabled_versions(plugin):
def is_version_of_plugin_deprecated(plugin, version):
lbs = plugin.version_labels
for iter_version, data in six.iteritems(lbs):
for iter_version, data in lbs.items():
if iter_version == version:
if data.get('deprecated', {'status': False}).get('status', False):
return True