diff options
author | daohanli <dhli5759@fiberhome.com> | 2017-03-30 11:24:05 +0800 |
---|---|---|
committer | daohanli <dhli5759@fiberhome.com> | 2017-03-30 13:38:26 +0800 |
commit | a594388fc16d86bb3c6b0c034b94e1dff7a4d1de (patch) | |
tree | 0c2126fe13a14befb1e3a15ad1aebf42c3b11991 /saharaclient | |
parent | 6e8ec4e7b0dada3791a6ccf1e54b2e9c9259f74c (diff) | |
download | python-saharaclient-a594388fc16d86bb3c6b0c034b94e1dff7a4d1de.tar.gz |
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: I8b181c1b049105fdd698385c4aba3546126a53dc
Diffstat (limited to 'saharaclient')
-rw-r--r-- | saharaclient/api/base.py | 9 | ||||
-rw-r--r-- | saharaclient/osc/v1/plugins.py | 7 | ||||
-rw-r--r-- | saharaclient/osc/v1/utils.py | 3 | ||||
-rw-r--r-- | saharaclient/tests/unit/base.py | 3 |
4 files changed, 9 insertions, 13 deletions
diff --git a/saharaclient/api/base.py b/saharaclient/api/base.py index 2674354..38a2848 100644 --- a/saharaclient/api/base.py +++ b/saharaclient/api/base.py @@ -16,7 +16,6 @@ import copy import json -import six from six.moves.urllib import parse from saharaclient._i18n import _ @@ -34,12 +33,12 @@ class Resource(object): self._add_details(info) def _set_defaults(self, info): - for name, value in six.iteritems(self.defaults): + for name, value in self.defaults.items(): if name not in info: info[name] = value 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 @@ -87,12 +86,12 @@ class ResourceManager(object): return found[0] def _copy_if_defined(self, data, **kwargs): - for var_name, var_value in six.iteritems(kwargs): + for var_name, var_value in kwargs.items(): if var_value is not None: data[var_name] = var_value def _copy_if_updated(self, data, **kwargs): - for var_name, var_value in six.iteritems(kwargs): + for var_name, var_value in kwargs.items(): if not isinstance(var_value, NotUpdated): data[var_name] = var_value diff --git a/saharaclient/osc/v1/plugins.py b/saharaclient/osc/v1/plugins.py index e38ba55..0ff3fa3 100644 --- a/saharaclient/osc/v1/plugins.py +++ b/saharaclient/osc/v1/plugins.py @@ -22,7 +22,6 @@ from osc_lib import exceptions from osc_lib import utils as osc_utils from oslo_log import log as logging from oslo_serialization import jsonutils -import six from saharaclient.osc.v1 import utils @@ -30,11 +29,11 @@ from saharaclient.osc.v1 import utils def _serialize_label_items(plugin): labels = {} pl_labels = plugin.get('plugin_labels', {}) - for label, data in six.iteritems(pl_labels): + for label, data in pl_labels.items(): labels['plugin: %s' % label] = data['status'] vr_labels = plugin.get('version_labels', {}) - for version, version_data in six.iteritems(vr_labels): - for label, data in six.iteritems(version_data): + for version, version_data in vr_labels.items(): + for label, data in version_data.items(): labels[ 'plugin version %s: %s' % (version, label)] = data['status'] labels = utils.prepare_data(labels, list(labels.keys())) diff --git a/saharaclient/osc/v1/utils.py b/saharaclient/osc/v1/utils.py index fd51450..714d96a 100644 --- a/saharaclient/osc/v1/utils.py +++ b/saharaclient/osc/v1/utils.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import six import time from oslo_utils import timeutils @@ -53,7 +52,7 @@ def get_resource_id(manager, name_or_id): def create_dict_from_kwargs(**kwargs): - return dict((k, v) for (k, v) in six.iteritems(kwargs) if v is not None) + return dict((k, v) for (k, v) in kwargs.items() if v is not None) def prepare_data(data, fields): diff --git a/saharaclient/tests/unit/base.py b/saharaclient/tests/unit/base.py index 209dcbe..c2cd255 100644 --- a/saharaclient/tests/unit/base.py +++ b/saharaclient/tests/unit/base.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six import testtools from saharaclient.api import base @@ -33,7 +32,7 @@ class BaseTestCase(testtools.TestCase): input_auth_token=self.TOKEN) def assertFields(self, body, obj): - for key, value in six.iteritems(body): + for key, value in body.items(): self.assertEqual(value, getattr(obj, key)) |