diff --git a/src/rougail/annotator/value.py b/src/rougail/annotator/value.py index 705052859..aeec99b54 100644 --- a/src/rougail/annotator/value.py +++ b/src/rougail/annotator/value.py @@ -62,20 +62,22 @@ class Annotator(Walk): # pylint: disable=R0903 variable: dict, ) -> None: multi = self.objectspace.multis.get(variable.path, False) - # variable's type inference from a default value with :term:`basic types` + + # default type inference from a default value with :term:`basic types` basic_types = {str: "string", int: "number", bool: "boolean", float: "float"} if variable.version == "1.0": # - version: 1.0, the default value is of type "string" by default if variable.type is None: variable.type = "string" - elif variable.version == "1.1": + else: #if variable.version != "1.0": # - version: 1.1, the default value has no type by default if multi is False and variable.type is None: if type(variable.default) in basic_types: variable.type = basic_types[type(variable.default)] else: - # XXX FIXME strange. weird. not good - variable.type = "string" + if variable.type is None: + variable.type = "string" + # a boolean must have value, the default value is "True" if variable.type == "boolean" and multi is False and variable.default is None: variable.default = True diff --git a/src/rougail/annotator/variable.py b/src/rougail/annotator/variable.py index e5ffa5f91..5e9a6d2df 100644 --- a/src/rougail/annotator/variable.py +++ b/src/rougail/annotator/variable.py @@ -79,6 +79,11 @@ class Annotator(Walk): # pylint: disable=R0903 for variable in self.get_variables(): if variable.type == "symlink": continue + # choice type inference from the `choices` attribute + if variable.version != "1.0": + if variable.choices is not None: + if variable.type is None: + variable.type = "choice" self._convert_variable(variable) def _convert_variable( diff --git a/src/rougail/convert.py b/src/rougail/convert.py index 11dd9c893..0f6a59217 100644 --- a/src/rougail/convert.py +++ b/src/rougail/convert.py @@ -56,7 +56,7 @@ from .object_model import ( Family, Dynamic, Variable, - Choice, + #Choice, SymLink, CALCULATION_TYPES, Calculation, @@ -237,7 +237,7 @@ class ParserVariable: # self.family = Family self.dynamic = Dynamic - self.choice = Choice + self.choice = Variable #Choice # self.exclude_imports = [] self.informations = Informations() diff --git a/src/rougail/object_model.py b/src/rougail/object_model.py index a9631dad7..1de66076a 100644 --- a/src/rougail/object_model.py +++ b/src/rougail/object_model.py @@ -442,13 +442,14 @@ class Variable(BaseModel): version: str # type will be set dynamically in `annotator/value.py`, default is None type: str = None + choices: Union[None, List[BASETYPE_CALC], Calculation] model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True) -class Choice(Variable): - type: Literal["choice"] = "choice" - choices: Union[List[BASETYPE_CALC], Calculation] +#class Choice(Variable): +# type: Literal["choice"] = "choice" +# choices: Union[List[BASETYPE_CALC], Calculation] class SymLink(BaseModel):