From 955b293403d76cfaa29349cc6de1c6249c8a2690 Mon Sep 17 00:00:00 2001 From: gwen Date: Tue, 4 Jun 2024 12:05:05 +0200 Subject: [PATCH] feat: default type inference --- src/rougail/annotator/value.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/rougail/annotator/value.py b/src/rougail/annotator/value.py index aeec99b54..6bfda4326 100644 --- a/src/rougail/annotator/value.py +++ b/src/rougail/annotator/value.py @@ -74,9 +74,19 @@ class Annotator(Walk): # pylint: disable=R0903 if multi is False and variable.type is None: if type(variable.default) in basic_types: variable.type = basic_types[type(variable.default)] - else: + 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 = "string" + 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: @@ -89,9 +99,9 @@ class Annotator(Walk): # pylint: disable=R0903 pass # variable.default = variable.default.to_function(self.functions) elif isinstance(variable.default, list): - if not multi: + if not multi and variable.version == "1.0": raise Exception( - f'The variable "{variable.path}" with a list has default value must have "multi" attribute' + f'The variable "{variable.path}" with a list as default value must have "multi" attribute' ) if variable.path in self.objectspace.followers: if multi != "submulti" and len(variable.default) != 1: