From 57f785250157d013a850a784ccc53b937f1273c4 Mon Sep 17 00:00:00 2001 From: gwen Date: Tue, 4 Jun 2024 16:21:18 +0200 Subject: [PATCH] feat: find automatically the type for a multi in case the "multi" attribute is not set, infers the type --- src/rougail/annotator/value.py | 26 -------------------------- src/rougail/annotator/variable.py | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/rougail/annotator/value.py b/src/rougail/annotator/value.py index 6bfda4326..a3981087b 100644 --- a/src/rougail/annotator/value.py +++ b/src/rougail/annotator/value.py @@ -62,32 +62,6 @@ class Annotator(Walk): # pylint: disable=R0903 variable: dict, ) -> None: multi = self.objectspace.multis.get(variable.path, False) - - # 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" - 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)] - elif isinstance(variable.default, list): - #if variable.name == "varname23": - # print("IIIIIIIIIIIIIIIIIIIIIIIIIIIII") - # print(variable.multi) - if variable.multi is None or variable.multi is False: - variable.multi = True - if variable.type is None: - variable.type = basic_types[type(variable.default[0])] - #if variable.name == "varname23": - # print(variable.multi) - # print(variable.type) - else: - 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 5e9a6d2df..2233faa3d 100644 --- a/src/rougail/annotator/variable.py +++ b/src/rougail/annotator/variable.py @@ -86,6 +86,29 @@ class Annotator(Walk): # pylint: disable=R0903 variable.type = "choice" self._convert_variable(variable) + multi = self.objectspace.multis.get(variable.path, False) + # 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" + 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)] + elif isinstance(variable.default, list): + if variable.multi is None or variable.multi is False: + variable.multi = True + if variable.type is None: + variable.type = basic_types[type(variable.default[0])] + #else: + # variable.type = "string" + # let's update the "multi" attribute in the tiramisu cache then + if variable.multi == True: + self.objectspace.multis[variable.path] = True + def _convert_variable( self, variable: dict,