mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 03:00:23 -07:00
Get rid of iteritems usage when we only care about the keys
This commit is contained in:
parent
fdf51e9a96
commit
63c54035de
1 changed files with 9 additions and 6 deletions
|
@ -97,6 +97,9 @@ class Base:
|
||||||
def munge(self, ds):
|
def munge(self, ds):
|
||||||
''' infrequently used method to do some pre-processing of legacy terms '''
|
''' infrequently used method to do some pre-processing of legacy terms '''
|
||||||
|
|
||||||
|
### FIXME: Can't find any classes with methods named
|
||||||
|
# _munge_base_class.__name__ so maybe Base.munge should be reduced down
|
||||||
|
# to return ds
|
||||||
for base_class in self.__class__.mro():
|
for base_class in self.__class__.mro():
|
||||||
method = getattr(self, "_munge_%s" % base_class.__name__.lower(), None)
|
method = getattr(self, "_munge_%s" % base_class.__name__.lower(), None)
|
||||||
if method:
|
if method:
|
||||||
|
@ -132,7 +135,7 @@ class Base:
|
||||||
# FIXME: we currently don't do anything with private attributes but
|
# FIXME: we currently don't do anything with private attributes but
|
||||||
# may later decide to filter them out of 'ds' here.
|
# may later decide to filter them out of 'ds' here.
|
||||||
|
|
||||||
for (name, attribute) in iteritems(self._get_base_attributes()):
|
for name in self._get_base_attributes():
|
||||||
# copy the value over unless a _load_field method is defined
|
# copy the value over unless a _load_field method is defined
|
||||||
if name in ds:
|
if name in ds:
|
||||||
method = getattr(self, '_load_%s' % name, None)
|
method = getattr(self, '_load_%s' % name, None)
|
||||||
|
@ -168,7 +171,7 @@ class Base:
|
||||||
not map to attributes for this object.
|
not map to attributes for this object.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
valid_attrs = [name for (name, attribute) in iteritems(self._get_base_attributes())]
|
valid_attrs = frozenset(name for name in self._get_base_attributes())
|
||||||
for key in ds:
|
for key in ds:
|
||||||
if key not in valid_attrs:
|
if key not in valid_attrs:
|
||||||
raise AnsibleParserError("'%s' is not a valid attribute for a %s" % (key, self.__class__.__name__), obj=ds)
|
raise AnsibleParserError("'%s' is not a valid attribute for a %s" % (key, self.__class__.__name__), obj=ds)
|
||||||
|
@ -191,7 +194,7 @@ class Base:
|
||||||
|
|
||||||
new_me = self.__class__()
|
new_me = self.__class__()
|
||||||
|
|
||||||
for (name, attribute) in iteritems(self._get_base_attributes()):
|
for name in self._get_base_attributes():
|
||||||
setattr(new_me, name, getattr(self, name))
|
setattr(new_me, name, getattr(self, name))
|
||||||
|
|
||||||
new_me._loader = self._loader
|
new_me._loader = self._loader
|
||||||
|
@ -262,7 +265,7 @@ class Base:
|
||||||
|
|
||||||
repr = dict()
|
repr = dict()
|
||||||
|
|
||||||
for (name, attribute) in iteritems(self._get_base_attributes()):
|
for name in self._get_base_attributes():
|
||||||
repr[name] = getattr(self, name)
|
repr[name] = getattr(self, name)
|
||||||
|
|
||||||
# serialize the uuid field
|
# serialize the uuid field
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue