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: Ic4fe5a3badfda93af11683215f0dad9b886e4791
This commit is contained in:
gengchc2
2016-12-09 10:50:43 +08:00
parent f1e7b9bf24
commit 11fae166d0
6 changed files with 8 additions and 13 deletions

View File

@@ -54,7 +54,7 @@ def load_auth_system_opts(parser):
""" """
group = parser.add_argument_group("Common auth options") group = parser.add_argument_group("Common auth options")
BaseAuthPlugin.add_common_opts(group) BaseAuthPlugin.add_common_opts(group)
for name, auth_plugin in six.iteritems(_discovered_plugins): for name, auth_plugin in _discovered_plugins.items():
group = parser.add_argument_group( group = parser.add_argument_group(
"Auth-system '%s' options" % name, "Auth-system '%s' options" % name,
conflict_handler="resolve") conflict_handler="resolve")

View File

@@ -304,7 +304,7 @@ class CrudManager(BaseManager):
def _filter_kwargs(self, kwargs): def _filter_kwargs(self, kwargs):
"""Drop null values and handle ids.""" """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: if ref is None:
kwargs.pop(key) kwargs.pop(key)
else: else:
@@ -462,7 +462,7 @@ class Resource(object):
return None return None
def _add_details(self, info): def _add_details(self, info):
for (k, v) in six.iteritems(info): for (k, v) in info.items():
try: try:
setattr(self, k, v) setattr(self, k, v)
self._info[k] = v self._info[k] = v

View File

@@ -23,7 +23,6 @@ Exception definitions.
import inspect import inspect
import sys import sys
import six
from solumclient.i18n import _ from solumclient.i18n import _
@@ -411,7 +410,7 @@ class HttpVersionNotSupported(HttpServerError):
# _code_map contains all the classes that have http_status attribute. # _code_map contains all the classes that have http_status attribute.
_code_map = dict( _code_map = dict(
(getattr(obj, 'http_status', None), obj) (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) if inspect.isclass(obj) and getattr(obj, 'http_status', False)
) )

View File

@@ -187,7 +187,7 @@ def print_dict(dct, dict_property="Property", wrap=0):
""" """
pt = prettytable.PrettyTable([dict_property, 'Value'], caching=False) pt = prettytable.PrettyTable([dict_property, 'Value'], caching=False)
pt.align = 'l' pt.align = 'l'
for k, v in six.iteritems(dct): for k, v in dct.items():
# convert dict to str to check length # convert dict to str to check length
if isinstance(v, dict): if isinstance(v, dict):
v = six.text_type(v) v = six.text_type(v)

View File

@@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import six
from solumclient.common.apiclient import exceptions from solumclient.common.apiclient import exceptions
from solumclient.common import exc from solumclient.common import exc
from solumclient.tests import base from solumclient.tests import base
@@ -23,7 +21,7 @@ class FakeResponse(object):
json_data = {} json_data = {}
def __init__(self, **kwargs): def __init__(self, **kwargs):
for key, value in six.iteritems(kwargs): for key, value in kwargs.items():
setattr(self, key, value) setattr(self, key, value)
def json(self): def json(self):

View File

@@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import six
from solumclient.common.apiclient import base as apiclient_base from solumclient.common.apiclient import base as apiclient_base
from solumclient.common.apiclient import exceptions from solumclient.common.apiclient import exceptions
from solumclient.common import base as solum_base from solumclient.common import base as solum_base
@@ -42,7 +40,7 @@ class Artifact(apiclient_base.Resource):
for res in req_list if req_list] for res in req_list if req_list]
def _add_details(self, info): def _add_details(self, info):
for (k, v) in six.iteritems(info): for (k, v) in info.items():
try: try:
if k == 'requirements': if k == 'requirements':
v = self._add_requirements_details(v) v = self._add_requirements_details(v)
@@ -66,7 +64,7 @@ class Plan(apiclient_base.Resource):
for res in serv_list if serv_list] for res in serv_list if serv_list]
def _add_details(self, info): def _add_details(self, info):
for (k, v) in six.iteritems(info): for (k, v) in info.items():
try: try:
if k == 'artifacts': if k == 'artifacts':
v = self._add_artifact_details(v) v = self._add_artifact_details(v)