From b133b85ec104219a76a405445a4506d71d4c1e77 Mon Sep 17 00:00:00 2001 From: gengchc2 Date: Fri, 9 Dec 2016 10:21:31 +0800 Subject: [PATCH] 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: I0c903ca9d566c89e4e0d6bd129dc1f7bc3e95db9 --- tripleo_common/exception.py | 2 +- tripleo_common/image/base.py | 5 +---- undercloud_heat_plugins/immutable_resources.py | 7 +++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/tripleo_common/exception.py b/tripleo_common/exception.py index a2fbbb3c4..16ca4c3c1 100644 --- a/tripleo_common/exception.py +++ b/tripleo_common/exception.py @@ -48,7 +48,7 @@ class TripleoCommonException(Exception): # kwargs doesn't match a variable in the message # log the issue and the kwargs LOG.exception(_LE('Exception in string format operation')) - for name, value in six.iteritems(kwargs): + for name, value in kwargs.items(): LOG.error(_LE("%(name)s: %(value)s"), {'name': name, 'value': value}) # noqa diff --git a/tripleo_common/image/base.py b/tripleo_common/image/base.py index 8a355013e..1083f81e0 100644 --- a/tripleo_common/image/base.py +++ b/tripleo_common/image/base.py @@ -12,9 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. - -import six - import json import os import yaml @@ -74,7 +71,7 @@ class BaseImageManager(object): attr) # If a new key is introduced, add it. - for key, value in six.iteritems(item): + for key, value in item.items(): if key not in existing_image: existing_image[key] = item[key] diff --git a/undercloud_heat_plugins/immutable_resources.py b/undercloud_heat_plugins/immutable_resources.py index 0d7b05d41..f8f15b075 100644 --- a/undercloud_heat_plugins/immutable_resources.py +++ b/undercloud_heat_plugins/immutable_resources.py @@ -13,7 +13,6 @@ import copy -import six from heat.engine.resources.openstack.neutron import net from heat.engine.resources.openstack.neutron import port @@ -32,7 +31,7 @@ class ImmutableNet(net.Net): properties_schema = { k: _copy_schema_immutable(v) - for k, v in six.iteritems(net.Net.properties_schema) + for k, v in net.Net.properties_schema.items() } @@ -41,7 +40,7 @@ class ImmutablePort(port.Port): properties_schema = { k: _copy_schema_immutable(v) - for k, v in six.iteritems(port.Port.properties_schema) + for k, v in port.Port.properties_schema.items() } @@ -50,7 +49,7 @@ class ImmutableSubnet(subnet.Subnet): properties_schema = { k: _copy_schema_immutable(v) - for k, v in six.iteritems(subnet.Subnet.properties_schema) + for k, v in subnet.Subnet.properties_schema.items() }