From c477796f42a22bea4261d6ff47f97823faa23427 Mon Sep 17 00:00:00 2001 From: rajat29 Date: Wed, 14 Jun 2017 13:21:00 +0530 Subject: [PATCH] Replace six.iteritems() with .items() 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 Python 3 as well, and it is more readable. In Python 2, the overhead of dict.items() creating a new list should be negligible for most use cases in OpenStack [2]. [1] https://wiki.openstack.org/wiki/Python3 [2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html Change-Id: I620c9cc201c62f033a5467aa52625b56e19933cb --- blazarclient/command.py | 6 +++--- blazarclient/utils.py | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/blazarclient/command.py b/blazarclient/command.py index 0ed7b00..b3e62df 100644 --- a/blazarclient/command.py +++ b/blazarclient/command.py @@ -84,7 +84,7 @@ class BlazarCommand(OpenStackCommand): return parser def format_output_data(self, data): - for k, v in six.iteritems(data): + for k, v in data.items(): if isinstance(v, six.text_type): try: # Deserialize if possible into dict, lists, tuples... @@ -134,7 +134,7 @@ class CreateCommand(BlazarCommand, show.ShowOne): print(self.app.stdout, 'Created a new %s:' % self.resource) else: data = {'': ''} - return zip(*sorted(six.iteritems(data))) + return zip(*sorted(data.items())) class UpdateCommand(BlazarCommand): @@ -291,4 +291,4 @@ class ShowCommand(BlazarCommand, show.ShowOne): resource_manager = getattr(blazar_client, self.resource) data = resource_manager.get(res_id) self.format_output_data(data) - return zip(*sorted(six.iteritems(data))) + return zip(*sorted(data.items())) diff --git a/blazarclient/utils.py b/blazarclient/utils.py index b428ff5..c8ca68b 100644 --- a/blazarclient/utils.py +++ b/blazarclient/utils.py @@ -17,7 +17,6 @@ import datetime import json import os import re -import six from blazarclient import exception from blazarclient.i18n import _ @@ -52,13 +51,13 @@ def to_primitive(value): return o elif isinstance(value, dict): o = {} - for k, v in six.iteritems(value): + for k, v in value.items(): o[k] = to_primitive(v) return o elif isinstance(value, datetime.datetime): return str(value) elif hasattr(value, 'iteritems'): - return to_primitive(dict(six.iteritems(value))) + return to_primitive(dict(value.items())) elif hasattr(value, '__iter__'): return to_primitive(list(value)) else: