From 20ae6d4418185111592094c134e55276f376bc49 Mon Sep 17 00:00:00 2001 From: "pawnesh.kumar" Date: Thu, 30 Mar 2017 15:33:33 +0530 Subject: [PATCH] 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 --- .../content/data_processing/data_plugins/tabs.py | 7 +++---- .../data_processing/data_plugins/workflows/update.py | 6 +++--- .../data_processing/jobs/job_templates/workflows/launch.py | 3 +-- .../content/data_processing/utils/workflow_helpers.py | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/sahara_dashboard/content/data_processing/data_plugins/tabs.py b/sahara_dashboard/content/data_processing/data_plugins/tabs.py index a6cbb4c7..4564442f 100644 --- a/sahara_dashboard/content/data_processing/data_plugins/tabs.py +++ b/sahara_dashboard/content/data_processing/data_plugins/tabs.py @@ -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), diff --git a/sahara_dashboard/content/data_processing/data_plugins/workflows/update.py b/sahara_dashboard/content/data_processing/data_plugins/workflows/update.py index 5c0728d8..8cbfae0d 100644 --- a/sahara_dashboard/content/data_processing/data_plugins/workflows/update.py +++ b/sahara_dashboard/content/data_processing/data_plugins/workflows/update.py @@ -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:] diff --git a/sahara_dashboard/content/data_processing/jobs/job_templates/workflows/launch.py b/sahara_dashboard/content/data_processing/jobs/job_templates/workflows/launch.py index 5826a4cd..da27ef67 100644 --- a/sahara_dashboard/content/data_processing/jobs/job_templates/workflows/launch.py +++ b/sahara_dashboard/content/data_processing/jobs/job_templates/workflows/launch.py @@ -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(): diff --git a/sahara_dashboard/content/data_processing/utils/workflow_helpers.py b/sahara_dashboard/content/data_processing/utils/workflow_helpers.py index 2e63c60c..90a0eb60 100644 --- a/sahara_dashboard/content/data_processing/utils/workflow_helpers.py +++ b/sahara_dashboard/content/data_processing/utils/workflow_helpers.py @@ -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