diff --git a/HACKING.rst b/HACKING.rst index 7075985e..760bcb18 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -9,3 +9,4 @@ Murano Specific Commandments - [M322] Method's default argument shouldn't be mutable. - [M323] Python 3: do not use dict.iteritems. - [M324] Python 3: do not use dict.iterkeys. +- [M325] Python 3: do not use dict.itervalues. diff --git a/murano/cmd/test_runner.py b/murano/cmd/test_runner.py index 188708f8..41ea8d1a 100755 --- a/murano/cmd/test_runner.py +++ b/murano/cmd/test_runner.py @@ -118,7 +118,7 @@ class MuranoTestRunner(object): m for m in class_to_methods[class_to_test] if m == test_method] continue - methods_count = sum(len(v) for v in methods_to_run.itervalues()) + methods_count = sum(len(v) for v in six.itervalues(methods_to_run)) methods = [k + '.' + method for k, v in six.iteritems(methods_to_run) for method in v] LOG.debug('{0} method(s) is(are) going to be executed: ' diff --git a/murano/common/utils.py b/murano/common/utils.py index a299cc2f..b7f1eae3 100644 --- a/murano/common/utils.py +++ b/murano/common/utils.py @@ -18,6 +18,7 @@ import functools as func import eventlet import jsonschema from oslo_log import log as logging +import six from murano.common.i18n import _, _LE @@ -198,7 +199,7 @@ def build_entity_map(value): if isinstance(value, dict): if '?' in value and 'id' in value['?']: id_map[value['?']['id']] = value - for v in value.itervalues(): + for v in six.itervalues(value): build_entity_map_recursive(v, id_map) if isinstance(value, list): for item in value: diff --git a/murano/dsl/executor.py b/murano/dsl/executor.py index 62cc2994..2fde7ad6 100644 --- a/murano/dsl/executor.py +++ b/murano/dsl/executor.py @@ -221,7 +221,7 @@ class MuranoDslExecutor(object): if (isinstance(sys_dict, dict) and sys_dict.get('id') and sys_dict.get('type')): yield sys_dict['id'] - for val in data.itervalues(): + for val in six.itervalues(data): for res in self._list_potential_object_ids(val): yield res elif isinstance(data, collections.Iterable) and not isinstance( diff --git a/murano/dsl/murano_class.py b/murano/dsl/murano_class.py index 7a43f1b8..84dd39dd 100644 --- a/murano/dsl/murano_class.py +++ b/murano/dsl/murano_class.py @@ -179,7 +179,7 @@ class MuranoClass(dsl_types.MuranoClass): def find_methods(self, predicate): result = [] for c in self.ancestors(): - for method in c.methods.itervalues(): + for method in six.itervalues(c.methods): if predicate(method) and method not in result: result.append(method) return result @@ -286,7 +286,7 @@ class MuranoClass(dsl_types.MuranoClass): (parent.package, requirement)) package_bindings = {} - for versions in aggregation.itervalues(): + for versions in six.itervalues(aggregation): mappings = self._remap_package(versions) package_bindings.update(mappings) diff --git a/murano/dsl/yaql_integration.py b/murano/dsl/yaql_integration.py index 1f226303..2e31ea89 100644 --- a/murano/dsl/yaql_integration.py +++ b/murano/dsl/yaql_integration.py @@ -252,7 +252,7 @@ def get_class_factory_definition(cls, murano_class): def filter_parameters(__fd, *args, **kwargs): if '*' not in __fd.parameters: position_args = 0 - for p in __fd.parameters.itervalues(): + for p in six.itervalues(__fd.parameters): if p.position is not None: position_args += 1 args = args[:position_args] @@ -261,7 +261,7 @@ def filter_parameters(__fd, *args, **kwargs): if not helpers.is_keyword(name): del kwargs[name] if '**' not in __fd.parameters: - names = {p.alias or p.name for p in __fd.parameters.itervalues()} + names = {p.alias or p.name for p in six.itervalues(__fd.parameters)} for name in kwargs.keys(): if name not in names: del kwargs[name] diff --git a/murano/engine/package_loader.py b/murano/engine/package_loader.py index ee6a63d6..0da2effa 100644 --- a/murano/engine/package_loader.py +++ b/murano/engine/package_loader.py @@ -261,8 +261,8 @@ class DirectoryPackageLoader(package_loader.MuranoPackageLoader): @property def packages(self): - for package_versions in self._packages_by_name.itervalues(): - for package in package_versions.itervalues(): + for package_versions in six.itervalues(self._packages_by_name): + for package in six.itervalues(package_versions): yield package @staticmethod diff --git a/murano/hacking/checks.py b/murano/hacking/checks.py index f97fde2b..f5805e37 100644 --- a/murano/hacking/checks.py +++ b/murano/hacking/checks.py @@ -49,7 +49,14 @@ def check_python3_no_iterkeys(logical_line): yield(0, msg) +def check_python3_no_itervalues(logical_line): + if re.search(r".*\.itervalues\(\)", logical_line): + msg = ("M325: Use six.itervalues() instead of dict.itervalues().") + yield(0, msg) + + def factory(register): register(no_mutable_default_args) register(check_python3_no_iteritems) register(check_python3_no_iterkeys) + register(check_python3_no_itervalues)