fix: type is not always mandatory
This commit is contained in:
parent
810d08822b
commit
ec86795768
1 changed files with 31 additions and 6 deletions
|
@ -590,7 +590,18 @@ class ParserVariable:
|
|||
extra_attrs = set(family_obj) - self.family_attrs
|
||||
if extra_attrs:
|
||||
raise Exception(f"extra attrs ... {extra_attrs}")
|
||||
if self.get_family_or_variable_type(family_obj) == "dynamic":
|
||||
obj_type = self.get_family_or_variable_type(family_obj)
|
||||
if obj_type is None:
|
||||
# auto set type
|
||||
if '_dynamic' in family_obj:
|
||||
dynamic = family_obj['_dynamic']
|
||||
elif 'dynamic' in family_obj:
|
||||
dynamic = family_obj['dynamic']
|
||||
else:
|
||||
dynamic = None
|
||||
if isinstance(dynamic, (list, dict)):
|
||||
family_obj['type'] = obj_type = 'dynamic'
|
||||
if obj_type == "dynamic":
|
||||
family_is_dynamic = True
|
||||
parent_dynamic = path
|
||||
if '{{ suffix }}' not in name:
|
||||
|
@ -999,11 +1010,16 @@ class ParserVariable:
|
|||
calculations = calculations[0]
|
||||
else:
|
||||
calculations = calculations[1]
|
||||
return (
|
||||
attribute in calculations
|
||||
and isinstance(value, dict)
|
||||
and value.get("type") in CALCULATION_TYPES
|
||||
)
|
||||
if not isinstance(value, dict) or attribute not in calculations:
|
||||
return False
|
||||
if 'type' in value:
|
||||
return value['type'] in CALCULATION_TYPES
|
||||
# auto set type
|
||||
typ = set(CALCULATION_TYPES) & set(value)
|
||||
if len(typ) == 1:
|
||||
value['type'] = list(typ)[0]
|
||||
return True
|
||||
return False
|
||||
|
||||
def set_calculation(
|
||||
self,
|
||||
|
@ -1036,6 +1052,11 @@ class ParserVariable:
|
|||
raise Exception("params must be a dict")
|
||||
params = []
|
||||
for key, val in calculation_object["params"].items():
|
||||
if isinstance(val, dict) and "type" not in val:
|
||||
# auto set type
|
||||
param_typ = set(CALCULATION_TYPES) & set(val)
|
||||
if len(param_typ) == 1:
|
||||
val['type'] = list(param_typ)[0]
|
||||
if not isinstance(val, dict) or "type" not in val:
|
||||
param_typ = "any"
|
||||
val = {
|
||||
|
@ -1214,6 +1235,8 @@ class RougailConvert(ParserVariable):
|
|||
objects,
|
||||
filename,
|
||||
)
|
||||
if objects is None:
|
||||
return
|
||||
self.parse_root_file(filename,
|
||||
path,
|
||||
version,
|
||||
|
@ -1268,6 +1291,8 @@ class RougailConvert(ParserVariable):
|
|||
filename: str,
|
||||
) -> None:
|
||||
"""version is mandatory in YAML file"""
|
||||
if obj is None:
|
||||
obj = {}
|
||||
for name in ["_version", "version"]:
|
||||
if name not in obj:
|
||||
continue
|
||||
|
|
Loading…
Reference in a new issue