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: Ied399c02ce35eb2c38de6129c24d46c25f6eb4b5
This commit is contained in:
Kiran_totad 2017-06-29 10:01:19 +05:30
parent d5da9d25ca
commit 7aa02f4dda
2 changed files with 3 additions and 3 deletions

View File

@ -230,7 +230,7 @@ def check_python3_no_iteritems(logical_line):
"compatible with both Python 2 and Python 3. In Python 2, "
"dict.items() may be inefficient for very large dictionaries. "
"If you can prove that you need the optimization of an "
"iterator for Python 2, then you can use six.iteritems(dict).")
"iterator for Python 2, then you can use dict.items().")
yield(0, msg)

View File

@ -192,7 +192,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 _add_methods(self, methods):
@ -203,7 +203,7 @@ class FakeResource(object):
@value. When users access the attribute with (), @value will be
returned, which looks like a function call.
"""
for (name, ret) in six.iteritems(methods):
for (name, ret) in methods.items():
method = mock.Mock(return_value=ret)
setattr(self, name, method)