mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
allow for lists, sets and dicts to default to None, now return empty type in post processing
remove defaults from inhertiable fieldattributes to allow for proper detection and override
This commit is contained in:
parent
3e13dfd7e8
commit
8aa732e0a4
1 changed files with 17 additions and 9 deletions
|
@ -51,8 +51,8 @@ class Base:
|
|||
_vars = FieldAttribute(isa='dict', default=dict())
|
||||
|
||||
# flags and misc. settings
|
||||
_environment = FieldAttribute(isa='list', default=[])
|
||||
_no_log = FieldAttribute(isa='bool', default=False)
|
||||
_environment = FieldAttribute(isa='list')
|
||||
_no_log = FieldAttribute(isa='bool')
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
@ -292,7 +292,9 @@ class Base:
|
|||
elif attribute.isa == 'bool':
|
||||
value = boolean(value)
|
||||
elif attribute.isa == 'list':
|
||||
if not isinstance(value, list):
|
||||
if value is None:
|
||||
value = []
|
||||
elif not isinstance(value, list):
|
||||
value = [ value ]
|
||||
if attribute.listof is not None:
|
||||
for item in value:
|
||||
|
@ -302,12 +304,18 @@ class Base:
|
|||
if item is None or item.strip() == "":
|
||||
raise AnsibleParserError("the field '%s' is required, and cannot have empty values" % (name,), obj=self.get_ds())
|
||||
elif attribute.isa == 'set':
|
||||
if not isinstance(value, (list, set)):
|
||||
value = [ value ]
|
||||
if not isinstance(value, set):
|
||||
value = set(value)
|
||||
elif attribute.isa == 'dict' and not isinstance(value, dict):
|
||||
raise TypeError("%s is not a dictionary" % value)
|
||||
if value is None:
|
||||
value = set()
|
||||
else:
|
||||
if not isinstance(value, (list, set)):
|
||||
value = [ value ]
|
||||
if not isinstance(value, set):
|
||||
value = set(value)
|
||||
elif attribute.isa == 'dict':
|
||||
if value is None:
|
||||
value = dict()
|
||||
elif not isinstance(value, dict):
|
||||
raise TypeError("%s is not a dictionary" % value)
|
||||
|
||||
# and assign the massaged value back to the attribute field
|
||||
setattr(self, name, value)
|
||||
|
|
Loading…
Reference in a new issue