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: I9cf36db9e18d02238ebbfa6962f0ac76d694a43a
This commit is contained in:
Arundhati Surpur 2017-08-23 15:25:05 +05:30 committed by Adrian Turjak
parent fee539e9ad
commit 5d1caeb37f
6 changed files with 8 additions and 14 deletions

View File

@ -24,7 +24,6 @@ import copy
from oslo_utils import reflection
from oslo_utils import strutils
import six
from six.moves.urllib import parse
from adjutantclient._i18n import _
@ -293,7 +292,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:
@ -451,7 +450,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

@ -13,7 +13,6 @@
# under the License.
import logging
import six
import json
from osc_lib.i18n import _
@ -28,7 +27,7 @@ def _show_notification(notification_id, client, formatter):
if formatter == 'table':
notification._info['notes'] = json.dumps(
notification.notes, indent=2)
return zip(*six.iteritems(notification.to_dict()))
return zip(*(notification.to_dict()).items())
class NotificationList(command.Lister):

View File

@ -13,9 +13,7 @@
# under the License.
import logging
import six
import json
from osc_lib.command import command
from osc_lib.i18n import _
@ -34,7 +32,7 @@ def _show_task(task_id, client, formatter):
getattr(task, 'action_notes', ""), indent=2)
task._info['approved_by'] = json.dumps(
getattr(task, 'approved_by', ""), indent=2)
return zip(*six.iteritems(task.to_dict()))
return zip(*(task.to_dict()).items())
class TaskList(command.Lister):

View File

@ -14,7 +14,6 @@
import logging
import json
import six
from osc_lib.command import command
from osc_lib.i18n import _
@ -75,7 +74,7 @@ class TokenShow(command.ShowOne):
else:
client = adjutant_client.Client("1", parsed_args.bypass_url)
token = client.tokens.get(parsed_args.token)
return zip(*six.iteritems(token.to_dict()))
return zip(*(token.to_dict()).items())
class TokenSubmit(command.Command):

View File

@ -13,7 +13,6 @@
# under the License.
import logging
import six
from osc_lib import utils
from osc_lib.command import command
@ -58,7 +57,7 @@ class UserShow(command.ShowOne):
# be better to do something slightly different here
user_id = utils.find_resource(client.users, parsed_args.user)
user = client.users.get(user_id)
return zip(*six.iteritems(user.to_dict()))
return zip(*(user.to_dict()).items())
class UserInvite(command.Command):

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from six.moves.urllib import parse
from adjutantclient.common import base
@ -75,7 +75,7 @@ class UserManager(base.ManagerWithFind):
# filters = kwargs.pop('filters')
# params.update(filters)
for key, value in six.iteritems(kwargs):
for key, value in (kwargs).items():
if value:
params[key] = value