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: Iff88f55dc51981ce502d7d3e67c467242980f20c
This commit is contained in:
Spencer Yu 2016-12-16 06:46:12 -08:00
parent c9bbe55355
commit 3b1ed4ec3e
11 changed files with 13 additions and 20 deletions

View File

@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import six
from oslo_config import cfg
from oslo_db import options
@ -43,7 +42,7 @@ def _get_facade():
cfg.CONF.database.connection,
sqlite_fk=True,
autocommit=False,
**dict(six.iteritems(cfg.CONF.database))
**dict(cfg.CONF.database.items())
)
if cfg.CONF.profiler.enabled:

View File

@ -12,14 +12,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
import sqlalchemy as sa
def apply_filters(query, model, **filters):
filter_dict = {}
for key, value in six.iteritems(filters):
for key, value in filters.items():
column_attr = getattr(model, key)
if isinstance(value, dict):
if 'in' in value:

View File

@ -14,7 +14,6 @@
# limitations under the License.
import copy
import six
from mistral.db.v2 import api as db_api
from mistral import exceptions as exc
@ -33,7 +32,7 @@ def validate_input(definition, input_dict, spec=None):
spec_input = (spec.get_input() if spec else
utils.get_dict_from_string(definition.input))
for p_name, p_value in six.iteritems(spec_input):
for p_name, p_value in spec_input.items():
if p_value is utils.NotDefined and p_name not in input_param_names:
missing_param_names.append(str(p_name))

View File

@ -219,7 +219,7 @@ class EventEngine(object):
trigger_info = trigger.to_dict()
self.event_triggers_map[trigger.event].append(trigger_info)
for (ex_t, events) in six.iteritems(self.exchange_topic_events_map):
for (ex_t, events) in self.exchange_topic_events_map.items():
exchange, topic = ex_t
self._add_event_listener(exchange, topic, events)

View File

@ -91,7 +91,7 @@ ENVIRONMENT_DB = db.Environment(
DATETIME_FORMAT)
)
ENVIRONMENT_DB_DICT = {k: v for k, v in six.iteritems(ENVIRONMENT_DB)}
ENVIRONMENT_DB_DICT = {k: v for k, v in ENVIRONMENT_DB.items()}
UPDATED_VARIABLES = copy.deepcopy(VARIABLES)
UPDATED_VARIABLES['host'] = '127.0.0.1'

View File

@ -23,7 +23,6 @@ import mock
from oslo_config import cfg
from oslo_log import log as logging
from oslotest import base
import six
import testtools.matchers as ttm
from mistral import context as auth_context
@ -127,7 +126,7 @@ class BaseTest(base.BaseTestCase):
def _assert_multiple_items(self, items, count, **props):
def _matches(item, **props):
for prop_name, prop_val in six.iteritems(props):
for prop_name, prop_val in props.items():
v = item[prop_name] if isinstance(
item, dict) else getattr(item, prop_name)
@ -160,7 +159,7 @@ class BaseTest(base.BaseTestCase):
missing = []
mismatched = []
for key, value in six.iteritems(expected):
for key, value in expected.items():
if key not in actual:
missing.append(key)
elif value != actual[key]:

View File

@ -22,7 +22,6 @@ import logging
import os
from os import path
import shutil
import six
import socket
import sys
import tempfile
@ -142,7 +141,7 @@ def merge_dicts(left, right, overwrite=True):
if right is None:
return left
for k, v in six.iteritems(right):
for k, v in right.items():
if k not in left:
left[k] = v
else:

View File

@ -22,7 +22,7 @@ def create_filters_from_request_params(**params):
:return: filters dictionary.
"""
filters = {}
for column, data in six.iteritems(params):
for column, data in params.items():
if data is not None:
if isinstance(data, six.string_types):
f_type, value = _extract_filter_type_and_value(data)

View File

@ -15,7 +15,6 @@
import copy
import datetime
import json
import six
from oslo_config import cfg
from oslo_log import log as logging
@ -40,7 +39,7 @@ def log_to_file(info, context=None):
db_info['params'] = {
k: str(v) if isinstance(v, datetime.datetime) else v
for k, v in six.iteritems(db_info.get('params', {}))
for k, v in db_info.get('params', {}).items()
}
attrs.append(json.dumps(db_info))

View File

@ -321,7 +321,7 @@ class BaseListSpec(BaseSpec):
self.items = []
for k, v in six.iteritems(data):
for k, v in data.items():
if k != 'version':
v['name'] = k
self._inject_version([k])
@ -354,7 +354,7 @@ class BaseSpecList(object):
def __init__(self, data):
self.items = {}
for k, v in six.iteritems(data):
for k, v in data.items():
if k != 'version':
v['name'] = k
v['version'] = self._version

View File

@ -17,7 +17,6 @@ import json
import os
import time
import six
from tempest import config
from tempest.lib import auth
@ -36,7 +35,7 @@ def get_resource(path):
def find_items(items, **props):
def _matches(item, **props):
for prop_name, prop_val in six.iteritems(props):
for prop_name, prop_val in props.items():
if item[prop_name] != prop_val:
return False