Python3: Replace dict.itervalues with six.itervalues

This also adds a check to murano/hacking/checks.py that should
catch this error in the future.

Blueprint murano-python-3-support

Change-Id: I50a8b2f98ddbc2819ae180b68468e0a51c13281b
This commit is contained in:
Ravi Shekhar Jethani 2016-01-18 03:04:23 -08:00
parent d99904e38b
commit e633fd004a
8 changed files with 18 additions and 9 deletions

View File

@ -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.

View File

@ -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: '

View File

@ -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:

View File

@ -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(

View File

@ -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)

View File

@ -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]

View File

@ -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

View File

@ -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)