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: Idb02425dbefb6ea9038b625d6286e377988b2c03
This commit is contained in:
melissaml 2016-11-29 11:23:16 +08:00
parent 5e94996791
commit fb3e26044d
6 changed files with 7 additions and 12 deletions

View File

@ -317,7 +317,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:
@ -476,7 +476,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

View File

@ -423,7 +423,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)
)

View File

@ -14,7 +14,6 @@
"""Searchlight v1 Facet action implementations"""
import logging
import six
from osc_lib.command import command
from osc_lib import utils
@ -63,7 +62,7 @@ class ListFacet(command.Lister):
}
data = search_client.facets.list(**params)
result = []
for resource_type, values in six.iteritems(data):
for resource_type, values in data.items():
if isinstance(values, list):
# Cope with pre-1.0 service APIs
facets = values

View File

@ -15,7 +15,6 @@
import json
import logging
import six
from osc_lib.command import command
from osc_lib import utils
@ -118,7 +117,7 @@ class SearchResource(command.Lister):
# hit._id may include extra information appended after _,
# so use r['_source']['id'] for safe.
r['_id'] = r.get('_source', {}).get('id')
for k, v in six.iteritems(r):
for k, v in r.items():
map_key = mapping.get(k)
if map_key is not None:
converted[map_key] = v

View File

@ -13,7 +13,6 @@
# under the License.
#
import six
import sys
@ -58,7 +57,7 @@ class FakeResource(object):
self._loaded = loaded
def _add_details(self, info):
for (k, v) in six.iteritems(info):
for (k, v) in info.items():
setattr(self, k, v)
def __repr__(self):

View File

@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from searchlightclient.common import base
@ -43,7 +41,7 @@ class SearchManager(base.BaseManager):
current project unless all_projects is set
"""
search_params = {}
for k, v in six.iteritems(kwargs):
for k, v in kwargs.items():
if k in ('query', 'type', 'offset',
'limit', 'sort', '_source', 'highlight', 'all_projects'):
search_params[k] = v