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: Ifac571e10ee48b119bc4bbb6a5d92200d0c7e482
This commit is contained in:
M V P Nitesh 2017-03-30 13:54:07 +05:30
parent aa875a3181
commit 0de0c4f2c8
4 changed files with 7 additions and 9 deletions

View File

@ -264,7 +264,7 @@ class Resource(RequestIdMixin):
self.append_request_ids(resp)
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

@ -406,7 +406,7 @@ class HttpVersionNotSupported(HttpServerError):
# _code_map contains all the classes that have status_code attribute.
_code_map = dict(
(getattr(obj, 'status_code', 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, 'status_code', False)
)

View File

@ -23,7 +23,6 @@ from osc_lib.cli import parseractions
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
from moganclient.common import base
from moganclient.common.i18n import _
@ -88,7 +87,7 @@ class CreateFlavor(command.ShowOne):
extra_specs = bc_client.flavor.get_extra_specs(data)
info.update(extra_specs)
return zip(*sorted(six.iteritems(info)))
return zip(*sorted(info.items()))
class DeleteFlavor(command.Command):
@ -260,7 +259,7 @@ class ShowFlavor(command.ShowOne):
info = {}
info.update(data._info)
return zip(*sorted(six.iteritems(info)))
return zip(*sorted(info.items()))
class UnsetFlavor(command.Command):

View File

@ -23,7 +23,6 @@ from osc_lib.cli import parseractions
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
from moganclient.common.i18n import _
@ -157,7 +156,7 @@ class CreateServer(command.ShowOne):
)
info = {}
info.update(data._info)
return zip(*sorted(six.iteritems(info)))
return zip(*sorted(info.items()))
class DeleteServer(command.Command):
@ -295,7 +294,7 @@ class ShowServer(command.ShowOne):
info = {}
info.update(data._info)
return zip(*sorted(six.iteritems(info)))
return zip(*sorted(info.items()))
class UpdateServer(command.ShowOne):
@ -381,7 +380,7 @@ class UpdateServer(command.ShowOne):
updates=updates)
info = {}
info.update(data._info)
return zip(*sorted(six.iteritems(info)))
return zip(*sorted(info.items()))
class StartServer(ServersActionBase):