From 5d1caeb37fbd7f55e8fbd89e3db49eacef74828f Mon Sep 17 00:00:00 2001 From: Arundhati Surpur Date: Wed, 23 Aug 2017 15:25:05 +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: I9cf36db9e18d02238ebbfa6962f0ac76d694a43a --- adjutantclient/common/base.py | 5 ++--- adjutantclient/osc/v1/notifications.py | 3 +-- adjutantclient/osc/v1/tasks.py | 4 +--- adjutantclient/osc/v1/tokens.py | 3 +-- adjutantclient/osc/v1/users.py | 3 +-- adjutantclient/v1/users.py | 4 ++-- 6 files changed, 8 insertions(+), 14 deletions(-) diff --git a/adjutantclient/common/base.py b/adjutantclient/common/base.py index b91ecaa..382fc89 100644 --- a/adjutantclient/common/base.py +++ b/adjutantclient/common/base.py @@ -24,7 +24,6 @@ import copy from oslo_utils import reflection from oslo_utils import strutils -import six from six.moves.urllib import parse from adjutantclient._i18n import _ @@ -293,7 +292,7 @@ class CrudManager(BaseManager): def _filter_kwargs(self, kwargs): """Drop null values and handle ids.""" - for key, ref in six.iteritems(kwargs.copy()): + for key, ref in (kwargs.copy().items()): if ref is None: kwargs.pop(key) else: @@ -451,7 +450,7 @@ class Resource(object): return None def _add_details(self, info): - for (k, v) in six.iteritems(info): + for (k, v) in (info).items(): try: setattr(self, k, v) self._info[k] = v diff --git a/adjutantclient/osc/v1/notifications.py b/adjutantclient/osc/v1/notifications.py index 4c92bd6..cb7fa61 100644 --- a/adjutantclient/osc/v1/notifications.py +++ b/adjutantclient/osc/v1/notifications.py @@ -13,7 +13,6 @@ # under the License. import logging -import six import json from osc_lib.i18n import _ @@ -28,7 +27,7 @@ def _show_notification(notification_id, client, formatter): if formatter == 'table': notification._info['notes'] = json.dumps( notification.notes, indent=2) - return zip(*six.iteritems(notification.to_dict())) + return zip(*(notification.to_dict()).items()) class NotificationList(command.Lister): diff --git a/adjutantclient/osc/v1/tasks.py b/adjutantclient/osc/v1/tasks.py index e173c2a..2382b21 100644 --- a/adjutantclient/osc/v1/tasks.py +++ b/adjutantclient/osc/v1/tasks.py @@ -13,9 +13,7 @@ # under the License. import logging -import six import json - from osc_lib.command import command from osc_lib.i18n import _ @@ -34,7 +32,7 @@ def _show_task(task_id, client, formatter): getattr(task, 'action_notes', ""), indent=2) task._info['approved_by'] = json.dumps( getattr(task, 'approved_by', ""), indent=2) - return zip(*six.iteritems(task.to_dict())) + return zip(*(task.to_dict()).items()) class TaskList(command.Lister): diff --git a/adjutantclient/osc/v1/tokens.py b/adjutantclient/osc/v1/tokens.py index f07df0e..da16381 100644 --- a/adjutantclient/osc/v1/tokens.py +++ b/adjutantclient/osc/v1/tokens.py @@ -14,7 +14,6 @@ import logging import json -import six from osc_lib.command import command from osc_lib.i18n import _ @@ -75,7 +74,7 @@ class TokenShow(command.ShowOne): else: client = adjutant_client.Client("1", parsed_args.bypass_url) token = client.tokens.get(parsed_args.token) - return zip(*six.iteritems(token.to_dict())) + return zip(*(token.to_dict()).items()) class TokenSubmit(command.Command): diff --git a/adjutantclient/osc/v1/users.py b/adjutantclient/osc/v1/users.py index 2b437ac..8f167f9 100644 --- a/adjutantclient/osc/v1/users.py +++ b/adjutantclient/osc/v1/users.py @@ -13,7 +13,6 @@ # under the License. import logging -import six from osc_lib import utils from osc_lib.command import command @@ -58,7 +57,7 @@ class UserShow(command.ShowOne): # be better to do something slightly different here user_id = utils.find_resource(client.users, parsed_args.user) user = client.users.get(user_id) - return zip(*six.iteritems(user.to_dict())) + return zip(*(user.to_dict()).items()) class UserInvite(command.Command): diff --git a/adjutantclient/v1/users.py b/adjutantclient/v1/users.py index f8dfc0f..09dd4d7 100644 --- a/adjutantclient/v1/users.py +++ b/adjutantclient/v1/users.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -import six + from six.moves.urllib import parse from adjutantclient.common import base @@ -75,7 +75,7 @@ class UserManager(base.ManagerWithFind): # filters = kwargs.pop('filters') # params.update(filters) - for key, value in six.iteritems(kwargs): + for key, value in (kwargs).items(): if value: params[key] = value