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
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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()))
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user