Replace six.iteritems() with .items()

1.As mentioned in [1], we should avoid using
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: I52b4ea9445143afc5e2f5f050373951a61a39327
This commit is contained in:
yfzhao 2017-03-30 23:52:13 +08:00
parent f80676fa83
commit 89b453be50
5 changed files with 6 additions and 7 deletions

View File

@ -594,7 +594,7 @@ class HostManager(object):
pool_key = '.'.join([host, pool.pool_name])
all_pools[pool_key] = pool
return six.itervalues(all_pools)
return all_pools.values()
def get_pools(self, context, filters=None):
"""Returns a dict of all pools on all hosts HostManager knows about."""

View File

@ -225,7 +225,7 @@ class GlusterManager(object):
raise exception.GlusterfsException(_(
'GlusterFS command %(command)s on volume %(volume)s failed'
) % {'volume': self.volume, 'command': command})
if list(six.itervalues(ret)) != [0, 0]:
if list(ret.values()) != [0, 0]:
errdct = {'volume': self.volume, 'command': commandstr,
'opErrstr': volxml_get(xmlout, 'opErrstr', default=None)}
errdct.update(ret)

View File

@ -298,7 +298,7 @@ class QnapAPIExecutor(object):
@_connection_checker
def get_share_info(self, pool_id, **kwargs):
"""Execute get_share_info API."""
for key, value in six.iteritems(kwargs):
for key, value in kwargs.items():
LOG.debug('%(key)s = %(val)s',
{'key': key, 'val': value})
@ -609,7 +609,7 @@ class QnapAPIExecutorTS(QnapAPIExecutor):
@_connection_checker
def get_snapshot_info(self, **kwargs):
"""Execute get_snapshot_info API."""
for key, value in six.iteritems(kwargs):
for key, value in kwargs.items():
LOG.debug('%(key)s = %(val)s',
{'key': key, 'val': value})

View File

@ -350,7 +350,7 @@ class TestCase(base_test.BaseTestCase):
def _dict_from_object(self, obj, ignored_keys):
if ignored_keys is None:
ignored_keys = []
return {k: v for k, v in obj.iteritems()
return {k: v for k, v in obj.items()
if k not in ignored_keys}
def _assertEqualListsOfObjects(self, objs1, objs2, ignored_keys=None):

View File

@ -14,7 +14,6 @@
# under the License.
import os
import six
import ddt
import mock
@ -127,7 +126,7 @@ class DataServiceHelperTestCase(test.TestCase):
data_copy_helper.CONF.data_node_access_ip = 'fake'
data_copy_helper.CONF.data_node_access_admin_user = 'fake'
expected = [{
'access_type': six.next(six.iteritems(mapping))[0],
'access_type': list(mapping.keys())[0],
'access_level': constants.ACCESS_LEVEL_RW,
'access_to': 'fake',
}]