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
|
extra_attrs = set(family_obj) - self.family_attrs
|
||||||
if extra_attrs:
|
if extra_attrs:
|
||||||
raise Exception(f"extra attrs ... {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
|
family_is_dynamic = True
|
||||||
parent_dynamic = path
|
parent_dynamic = path
|
||||||
if '{{ suffix }}' not in name:
|
if '{{ suffix }}' not in name:
|
||||||
|
@ -999,11 +1010,16 @@ class ParserVariable:
|
||||||
calculations = calculations[0]
|
calculations = calculations[0]
|
||||||
else:
|
else:
|
||||||
calculations = calculations[1]
|
calculations = calculations[1]
|
||||||
return (
|
if not isinstance(value, dict) or attribute not in calculations:
|
||||||
attribute in calculations
|
return False
|
||||||
and isinstance(value, dict)
|
if 'type' in value:
|
||||||
and value.get("type") in CALCULATION_TYPES
|
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(
|
def set_calculation(
|
||||||
self,
|
self,
|
||||||
|
@ -1036,6 +1052,11 @@ class ParserVariable:
|
||||||
raise Exception("params must be a dict")
|
raise Exception("params must be a dict")
|
||||||
params = []
|
params = []
|
||||||
for key, val in calculation_object["params"].items():
|
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:
|
if not isinstance(val, dict) or "type" not in val:
|
||||||
param_typ = "any"
|
param_typ = "any"
|
||||||
val = {
|
val = {
|
||||||
|
@ -1214,6 +1235,8 @@ class RougailConvert(ParserVariable):
|
||||||
objects,
|
objects,
|
||||||
filename,
|
filename,
|
||||||
)
|
)
|
||||||
|
if objects is None:
|
||||||
|
return
|
||||||
self.parse_root_file(filename,
|
self.parse_root_file(filename,
|
||||||
path,
|
path,
|
||||||
version,
|
version,
|
||||||
|
@ -1268,6 +1291,8 @@ class RougailConvert(ParserVariable):
|
||||||
filename: str,
|
filename: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""version is mandatory in YAML file"""
|
"""version is mandatory in YAML file"""
|
||||||
|
if obj is None:
|
||||||
|
obj = {}
|
||||||
for name in ["_version", "version"]:
|
for name in ["_version", "version"]:
|
||||||
if name not in obj:
|
if name not in obj:
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue