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: I6368133635a1f56bc923e633be683bcdda36eeb3
This commit is contained in:
parent
35de1df1eb
commit
b59b33a5b6
|
@ -173,7 +173,7 @@ class CheckCodeStructure(object):
|
|||
yield self._check_mappings[check](value)
|
||||
|
||||
def _check_structure(self, block):
|
||||
for key, value in six.iteritems(CODE_STRUCTURE):
|
||||
for key, value in CODE_STRUCTURE.items():
|
||||
if key in block:
|
||||
break
|
||||
else:
|
||||
|
@ -195,13 +195,13 @@ class CheckCodeStructure(object):
|
|||
for unknown in (block_keys_set - kset - {key}):
|
||||
yield error.report.E201('Unknown keyword "{0}" in "{1}"'
|
||||
.format(unknown, key), unknown)
|
||||
for ckey, cvalue in six.iteritems(keywords):
|
||||
for ckey, cvalue in keywords.items():
|
||||
check = cvalue['check']
|
||||
data = block.get(ckey)
|
||||
if not data:
|
||||
continue
|
||||
if isinstance(check, tuple):
|
||||
for left, right in six.iteritems(data):
|
||||
for left, right in data.items():
|
||||
yield self._run_check(check[0], left)
|
||||
yield self._run_check(check[1], right)
|
||||
else:
|
||||
|
|
|
@ -118,14 +118,14 @@ class YamlValidator(BaseValidator):
|
|||
file_check = self._checkers.get(None)
|
||||
if file_check:
|
||||
run_helper(None, file_check['checkers'], ast)
|
||||
for key, value in six.iteritems(ast):
|
||||
for key, value in ast.items():
|
||||
checkers = self._checkers.get(key)
|
||||
if checkers:
|
||||
run_helper(key, checkers['checkers'], ast[key])
|
||||
else:
|
||||
reports_chain.append(self._unknown_keyword(key, value))
|
||||
missing = set(key for key, value in
|
||||
six.iteritems(self._checkers)
|
||||
self._checkers.items()
|
||||
if value['required']) - set(ast.keys())
|
||||
for m in missing:
|
||||
reports_chain.append([
|
||||
|
|
|
@ -88,7 +88,7 @@ class ManifestValidator(base.YamlValidator):
|
|||
if not isinstance(value, dict):
|
||||
yield error.report.E005(_('Require is not a dict type'), value)
|
||||
return
|
||||
for fqn, ver in six.iteritems(value):
|
||||
for fqn, ver in value.items():
|
||||
if not self._check_fqn_name(fqn):
|
||||
yield error.report.E005(_('Require key is not valid FQN "{}"'
|
||||
'').format(fqn), fqn)
|
||||
|
|
|
@ -153,7 +153,7 @@ class MuranoPLValidator(base.YamlValidator):
|
|||
elif isinstance(contract, dict):
|
||||
if not contract:
|
||||
return
|
||||
for c_key, c_value in six.iteritems(contract):
|
||||
for c_key, c_value in contract.items():
|
||||
yield self._valid_string(c_key)
|
||||
yield self._valid_contract(c_value)
|
||||
elif isinstance(contract, six.string_types):
|
||||
|
@ -170,7 +170,7 @@ class MuranoPLValidator(base.YamlValidator):
|
|||
yield error.report.E026(_('Properties should be a dict'),
|
||||
properties)
|
||||
return
|
||||
for property_name, property_data in six.iteritems(properties):
|
||||
for property_name, property_data in properties.items():
|
||||
usage = property_data.get('Usage')
|
||||
if usage:
|
||||
if usage not in PROPERTIES_USAGE_VALUES:
|
||||
|
@ -190,7 +190,7 @@ class MuranoPLValidator(base.YamlValidator):
|
|||
yield error.report.E044(_('Wrong type of namespace'), value)
|
||||
return
|
||||
|
||||
for name, fqn in six.iteritems(value):
|
||||
for name, fqn in value.items():
|
||||
if not self._check_fqn_name(fqn):
|
||||
yield error.report.W060(_('Wrong namespace fqn '
|
||||
'"{}"').format(fqn), fqn)
|
||||
|
@ -204,7 +204,7 @@ class MuranoPLValidator(base.YamlValidator):
|
|||
yield error.report.E046(_('Methods are not a dict'),
|
||||
value)
|
||||
return
|
||||
for method_name, method_data in six.iteritems(value):
|
||||
for method_name, method_data in value.items():
|
||||
if not isinstance(method_data, dict):
|
||||
if method_data:
|
||||
yield error.report.E046(_('Method is not a dict'),
|
||||
|
|
|
@ -49,7 +49,7 @@ class UiValidator(base.YamlValidator):
|
|||
yield error.report.E084(_('Application is not a dict'),
|
||||
application)
|
||||
return
|
||||
for name, value in six.iteritems(application):
|
||||
for name, value in application.items():
|
||||
if not self._check_name(name):
|
||||
if name != '?':
|
||||
yield error.report.E083(_('Wrong name in UI file "{}"')
|
||||
|
@ -62,14 +62,14 @@ class UiValidator(base.YamlValidator):
|
|||
|
||||
def _valid_forms(self, forms):
|
||||
for named_form in forms:
|
||||
for name, form in six.iteritems(named_form):
|
||||
for name, form in named_form.items():
|
||||
yield self._valid_form(form['fields'])
|
||||
yield self._valid_keywords(form.keys(),
|
||||
('fields', 'validators'))
|
||||
|
||||
def _valid_form(self, form):
|
||||
for named_params in form:
|
||||
for key, value in six.iteritems(named_params):
|
||||
for key, value in named_params.items():
|
||||
if key in STR_FIELDS:
|
||||
if not isinstance(value, six.string_types):
|
||||
yield error.report.E040(_('Value of {} should be '
|
||||
|
|
Loading…
Reference in New Issue