From 3b1ed4ec3ed7b082bded1163d9400e6617cd1c85 Mon Sep 17 00:00:00 2001 From: Spencer Yu Date: Fri, 16 Dec 2016 06:46:12 -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: Iff88f55dc51981ce502d7d3e67c467242980f20c --- mistral/db/sqlalchemy/base.py | 3 +-- mistral/db/v2/sqlalchemy/filters.py | 3 +-- mistral/engine/utils.py | 3 +-- mistral/event_engine/event_engine.py | 2 +- mistral/tests/unit/api/v2/test_environment.py | 2 +- mistral/tests/unit/base.py | 5 ++--- mistral/utils/__init__.py | 3 +-- mistral/utils/filter_utils.py | 2 +- mistral/utils/profiler.py | 3 +-- mistral/workbook/base.py | 4 ++-- mistral_tempest_tests/services/base.py | 3 +-- 11 files changed, 13 insertions(+), 20 deletions(-) diff --git a/mistral/db/sqlalchemy/base.py b/mistral/db/sqlalchemy/base.py index 0cf570773..3f04b5249 100644 --- a/mistral/db/sqlalchemy/base.py +++ b/mistral/db/sqlalchemy/base.py @@ -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: diff --git a/mistral/db/v2/sqlalchemy/filters.py b/mistral/db/v2/sqlalchemy/filters.py index 724baa775..bcd3e47c6 100644 --- a/mistral/db/v2/sqlalchemy/filters.py +++ b/mistral/db/v2/sqlalchemy/filters.py @@ -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: diff --git a/mistral/engine/utils.py b/mistral/engine/utils.py index c31f27316..df19ba015 100644 --- a/mistral/engine/utils.py +++ b/mistral/engine/utils.py @@ -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)) diff --git a/mistral/event_engine/event_engine.py b/mistral/event_engine/event_engine.py index c34a06965..4f48d6fb0 100644 --- a/mistral/event_engine/event_engine.py +++ b/mistral/event_engine/event_engine.py @@ -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) diff --git a/mistral/tests/unit/api/v2/test_environment.py b/mistral/tests/unit/api/v2/test_environment.py index b9af07219..d5d8148c3 100644 --- a/mistral/tests/unit/api/v2/test_environment.py +++ b/mistral/tests/unit/api/v2/test_environment.py @@ -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' diff --git a/mistral/tests/unit/base.py b/mistral/tests/unit/base.py index 91ac75eb6..c2a6f8d1b 100644 --- a/mistral/tests/unit/base.py +++ b/mistral/tests/unit/base.py @@ -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]: diff --git a/mistral/utils/__init__.py b/mistral/utils/__init__.py index a9c337a01..4ec935663 100644 --- a/mistral/utils/__init__.py +++ b/mistral/utils/__init__.py @@ -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: diff --git a/mistral/utils/filter_utils.py b/mistral/utils/filter_utils.py index 4d697b26f..5d60057b0 100644 --- a/mistral/utils/filter_utils.py +++ b/mistral/utils/filter_utils.py @@ -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) diff --git a/mistral/utils/profiler.py b/mistral/utils/profiler.py index 6b9360e51..f0963c365 100644 --- a/mistral/utils/profiler.py +++ b/mistral/utils/profiler.py @@ -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)) diff --git a/mistral/workbook/base.py b/mistral/workbook/base.py index 19e34aa4d..0c8c06e6d 100644 --- a/mistral/workbook/base.py +++ b/mistral/workbook/base.py @@ -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 diff --git a/mistral_tempest_tests/services/base.py b/mistral_tempest_tests/services/base.py index 8da3928cf..02c534ab9 100644 --- a/mistral_tempest_tests/services/base.py +++ b/mistral_tempest_tests/services/base.py @@ -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