doc for valid_enum

This commit is contained in:
2021-02-24 19:22:07 +01:00
parent 54bf1c35a7
commit 46ba8c8067
12 changed files with 114 additions and 10 deletions

View File

@ -110,7 +110,7 @@ class CheckAnnotator(TargetAnnotator, ParamAnnotator):
# check value
self.check_valid_enum_value(target.name, values)
else:
# no value, set the first choice has default value
# no value, set the first choice as default value
new_value = self.objectspace.value(check.xmlfiles)
new_value.name = values[0]
new_value.type = variable_type
@ -124,8 +124,6 @@ class CheckAnnotator(TargetAnnotator, ParamAnnotator):
variable,
check,
) -> List[Any]:
# value for choice's variable is mandatory
variable.mandatory = True
# build choice
variable.values = []
variable.ori_type = variable.type
@ -133,6 +131,7 @@ class CheckAnnotator(TargetAnnotator, ParamAnnotator):
has_variable = False
values = []
has_nil = False
for param in check.param:
if has_variable:
msg = _(f'only one "variable" parameter is allowed for valid_enum '
@ -150,15 +149,22 @@ class CheckAnnotator(TargetAnnotator, ParamAnnotator):
f'of variable "{variable.name}"')
raise DictConsistencyError(msg, 6, param.xmlfiles)
param_type = 'calculation'
elif param.type == 'nil':
has_nil = True
values.append(param.text)
choice = self.objectspace.choice(variable.xmlfiles)
choice.name = param.text
choice.type = param_type
variable.values.append(choice)
if 'mandatory' not in vars(variable):
variable.mandatory = not has_nil
elif variable.mandatory is False:
choice = self.objectspace.choice(variable.xmlfiles)
choice.name = None
choice.type = 'nil'
variable.values.append(choice)
if has_variable:
return None
for target in check.target:
self.objectspace.valid_enums[target.name.path] = {'type': variable.ori_type,
'values': values,