From 0b1f7efefe519db80373adfb05f61c127700c478 Mon Sep 17 00:00:00 2001 From: Kiran_totad Date: Mon, 24 Jul 2017 12:33:49 +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: I43d1d93817fa533fdfc68893008a2921eb09ddcf --- distilclient/common/apiclient/base.py | 4 ++-- distilclient/common/apiclient/exceptions.py | 2 +- distilclient/common/cliutils.py | 2 +- distilclient/v2/client.py | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/distilclient/common/apiclient/base.py b/distilclient/common/apiclient/base.py index 58c62a4..6811a35 100644 --- a/distilclient/common/apiclient/base.py +++ b/distilclient/common/apiclient/base.py @@ -303,7 +303,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: @@ -461,7 +461,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/distilclient/common/apiclient/exceptions.py b/distilclient/common/apiclient/exceptions.py index 02df63b..16d311e 100644 --- a/distilclient/common/apiclient/exceptions.py +++ b/distilclient/common/apiclient/exceptions.py @@ -421,7 +421,7 @@ class HttpVersionNotSupported(HttpServerError): # _code_map contains all the classes that have http_status attribute. _code_map = dict( (getattr(obj, 'http_status', None), obj) - for name, obj in six.iteritems(vars(sys.modules[__name__])) + for name, obj in vars(sys.modules[__name__]).items() if inspect.isclass(obj) and getattr(obj, 'http_status', False) ) diff --git a/distilclient/common/cliutils.py b/distilclient/common/cliutils.py index cff3db5..67bc452 100644 --- a/distilclient/common/cliutils.py +++ b/distilclient/common/cliutils.py @@ -195,7 +195,7 @@ def print_dict(dct, dict_property="Property", wrap=0): """ pt = prettytable.PrettyTable([dict_property, 'Value']) pt.align = 'l' - for k, v in six.iteritems(dct): + for k, v in dct.items(): # convert dict to str to check length if isinstance(v, dict): v = six.text_type(v) diff --git a/distilclient/v2/client.py b/distilclient/v2/client.py index afb9676..4b7290d 100644 --- a/distilclient/v2/client.py +++ b/distilclient/v2/client.py @@ -16,7 +16,6 @@ from keystoneclient import adapter from keystoneclient import client as ks_client from keystoneclient import discover from keystoneclient import session -import six from distilclient.common import httpclient from distilclient import exceptions @@ -109,7 +108,7 @@ class Client(object): 'api_key': 'password', } - for arg, replacement in six.iteritems(deprecated): + for arg, replacement in deprecated.items(): if kwargs.get(arg, None) is None: continue