feat: default type inference

This commit is contained in:
gwen 2024-06-04 12:05:05 +02:00
parent 035fd7bd7e
commit 955b293403

View file

@ -74,9 +74,19 @@ class Annotator(Walk): # pylint: disable=R0903
if multi is False and variable.type is None: if multi is False and variable.type is None:
if type(variable.default) in basic_types: if type(variable.default) in basic_types:
variable.type = basic_types[type(variable.default)] 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: 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" # a boolean must have value, the default value is "True"
if variable.type == "boolean" and multi is False and variable.default is None: if variable.type == "boolean" and multi is False and variable.default is None:
@ -89,9 +99,9 @@ class Annotator(Walk): # pylint: disable=R0903
pass pass
# variable.default = variable.default.to_function(self.functions) # variable.default = variable.default.to_function(self.functions)
elif isinstance(variable.default, list): elif isinstance(variable.default, list):
if not multi: if not multi and variable.version == "1.0":
raise Exception( 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 variable.path in self.objectspace.followers:
if multi != "submulti" and len(variable.default) != 1: if multi != "submulti" and len(variable.default) != 1: