add port_type example
This commit is contained in:
@ -235,8 +235,16 @@ class ConditionAnnotator(TargetAnnotator, ParamAnnotator, Walk):
|
||||
or_needed = len(condition.param) != 1
|
||||
if len(condition.param) == 1:
|
||||
values = getattr(condition.param[0], 'text', None)
|
||||
param_type = condition.param[0].type
|
||||
else:
|
||||
values = tuple([getattr(param, 'text', None) for param in condition.param])
|
||||
param_type = None
|
||||
for param in condition.param:
|
||||
if param_type is None or param_type == 'nil':
|
||||
param_type = param.type
|
||||
if param_type != param.type:
|
||||
msg = _(f'param with type "{target.type}" has multi param types')
|
||||
raise DictConsistencyError(msg, 59, condition.xmlfiles)
|
||||
param3 = self.objectspace.param(target.xmlfiles)
|
||||
param3.name = f'condition_{fill.index}'
|
||||
param3.type = 'variable'
|
||||
@ -245,7 +253,7 @@ class ConditionAnnotator(TargetAnnotator, ParamAnnotator, Walk):
|
||||
param4 = self.objectspace.param(target.xmlfiles)
|
||||
param4.name = f'expected_{fill.index}'
|
||||
param4.text = values
|
||||
param4.type = condition.param[0].type
|
||||
param4.type = param_type
|
||||
fill.param.append(param4)
|
||||
if condition.name != 'disabled_if_in':
|
||||
param5 = self.objectspace.param(target.xmlfiles)
|
||||
|
@ -45,54 +45,68 @@ class ParamAnnotator:
|
||||
param_to_delete = []
|
||||
variable_type = self.valid_type_validation(obj)
|
||||
for param_idx, param in enumerate(obj.param):
|
||||
if param.type == 'suffix':
|
||||
if hasattr(param, 'text'):
|
||||
if hasattr(param, 'text'):
|
||||
if param.type == 'suffix':
|
||||
msg = _(f'"{param.type}" parameter must not have a value')
|
||||
raise DictConsistencyError(msg, 28, obj.xmlfiles)
|
||||
elif param.type == 'nil':
|
||||
if param.text is not None:
|
||||
msg = _(f'"{param.type}" parameter must not have a value')
|
||||
raise DictConsistencyError(msg, 40, obj.xmlfiles)
|
||||
elif param.type == 'variable':
|
||||
try:
|
||||
path, suffix = self.objectspace.paths.get_variable_path(param.text,
|
||||
obj.namespace,
|
||||
)
|
||||
param.text = self.objectspace.paths.get_variable(path)
|
||||
if variable_type and param.text.type != variable_type:
|
||||
msg = _(f'"{obj.name}" has type "{variable_type}" but param has type "{param.text.type}"')
|
||||
raise DictConsistencyError(msg, 26, param.xmlfiles)
|
||||
if suffix:
|
||||
param.suffix = suffix
|
||||
family_path = self.objectspace.paths.get_variable_family_path(path)
|
||||
param.family = self.objectspace.paths.get_family(family_path,
|
||||
param.text.namespace,
|
||||
)
|
||||
except DictConsistencyError as err:
|
||||
if err.errno != 42 or not param.optional:
|
||||
raise err
|
||||
param_to_delete.append(param_idx)
|
||||
elif variable_type:
|
||||
self._convert_with_variable_type(variable_type, param)
|
||||
continue
|
||||
# no param.text
|
||||
if param.type == 'suffix':
|
||||
for target in obj.target:
|
||||
if not self.objectspace.paths.variable_is_dynamic(target.name.path):
|
||||
msg = _(f'"suffix" parameter cannot be set with target "{target.name}"'
|
||||
f' which is not a dynamic variable')
|
||||
raise DictConsistencyError(msg, 53, obj.xmlfiles)
|
||||
elif not hasattr(param, 'text'):
|
||||
if not param.type == 'nil':
|
||||
msg = _(f'"{param.type}" parameter must have a value')
|
||||
raise DictConsistencyError(msg, 27, obj.xmlfiles)
|
||||
param.text = None
|
||||
elif param.type == 'nil':
|
||||
msg = _(f'"{param.type}" parameter must not have a value')
|
||||
raise DictConsistencyError(msg, 40, obj.xmlfiles)
|
||||
elif param.type == 'variable':
|
||||
try:
|
||||
path, suffix = self.objectspace.paths.get_variable_path(param.text,
|
||||
obj.namespace,
|
||||
)
|
||||
param.text = self.objectspace.paths.get_variable(path)
|
||||
if variable_type and param.text.type != variable_type:
|
||||
msg = _(f'"{obj.name}" has type "{variable_type}" but param has type "{param.text.type}"')
|
||||
raise DictConsistencyError(msg, 26, param.xmlfiles)
|
||||
if suffix:
|
||||
param.suffix = suffix
|
||||
family_path = self.objectspace.paths.get_variable_family_path(path)
|
||||
param.family = self.objectspace.paths.get_family(family_path,
|
||||
param.text.namespace,
|
||||
)
|
||||
except DictConsistencyError as err:
|
||||
if err.errno != 42 or not param.optional:
|
||||
raise err
|
||||
param_to_delete.append(param_idx)
|
||||
elif variable_type:
|
||||
if 'type' in vars(param) and variable_type != param.type:
|
||||
msg = _(f'parameter has incompatible type "{param.type}" '
|
||||
f'with type "{variable_type}"')
|
||||
raise DictConsistencyError(msg, 7, param.xmlfiles)
|
||||
try:
|
||||
param.text = CONVERT_OPTION[variable_type].get('func', str)(param.text)
|
||||
except ValueError as err:
|
||||
msg = _(f'unable to change type of "{param.text}" '
|
||||
f'is not a valid "{variable_type}"')
|
||||
raise DictConsistencyError(msg, 13, param.xmlfiles) from err
|
||||
param.type = variable_type
|
||||
param.text = None
|
||||
elif param.type == 'string':
|
||||
param.text = ''
|
||||
if variable_type:
|
||||
self._convert_with_variable_type(variable_type, param)
|
||||
else:
|
||||
msg = _(f'"{param.type}" parameter must have a value')
|
||||
raise DictConsistencyError(msg, 27, obj.xmlfiles)
|
||||
param_to_delete.sort(reverse=True)
|
||||
for param_idx in param_to_delete:
|
||||
obj.param.pop(param_idx)
|
||||
|
||||
def _convert_with_variable_type(self,
|
||||
variable_type: str,
|
||||
param: 'self.objectspace.param',
|
||||
) -> None:
|
||||
if 'type' in vars(param) and variable_type != param.type:
|
||||
msg = _(f'parameter has incompatible type "{param.type}" '
|
||||
f'with type "{variable_type}"')
|
||||
raise DictConsistencyError(msg, 7, param.xmlfiles)
|
||||
try:
|
||||
param.text = CONVERT_OPTION[variable_type].get('func', str)(param.text)
|
||||
except ValueError as err:
|
||||
msg = _(f'unable to change type of "{param.text}" '
|
||||
f'is not a valid "{variable_type}"')
|
||||
raise DictConsistencyError(msg, 13, param.xmlfiles) from err
|
||||
param.type = variable_type
|
||||
|
@ -242,7 +242,7 @@ class Common:
|
||||
):
|
||||
"""Populate variable parameters
|
||||
"""
|
||||
if param.type in ['number', 'boolean', 'nil', 'string']:
|
||||
if param.type in ['number', 'boolean', 'nil', 'string', 'port']:
|
||||
value = param.text
|
||||
if param.type == 'string' and value is not None:
|
||||
value = self.convert_str(value)
|
||||
|
Reference in New Issue
Block a user