feat: add default inference behavior for basic types #13
3 changed files with 16 additions and 11 deletions
|
@ -62,17 +62,20 @@ class Annotator(Walk): # pylint: disable=R0903
|
||||||
variable: dict,
|
variable: dict,
|
||||||
) -> None:
|
) -> None:
|
||||||
multi = self.objectspace.multis.get(variable.path, False)
|
multi = self.objectspace.multis.get(variable.path, False)
|
||||||
|
# variable's type inference from a default value with :term:`basic types`
|
||||||
types = {str: "string", int: "number", bool: "boolean", float: "float"}
|
basic_types = {str: "string", int: "number", bool: "boolean", float: "float"}
|
||||||
|
if variable.version == "1.0":
|
||||||
# variable's type inference with a default value with a basic type
|
# - version: 1.0, the default value is of type "string" by default
|
||||||
## XXX hack: convert None to string
|
if variable.type is None:
|
||||||
|
|||||||
variable.type = "string"
|
variable.type = "string"
|
||||||
## XXX gérer le comportement suivant les versions
|
elif variable.version == "1.1":
|
||||||
egarette
commented
Not only 1.1, should be "else:" Not only 1.1, should be "else:"
|
|||||||
if multi is False and variable.type == "string" and type(variable.default) != str:
|
# - version: 1.1, the default value has no type by default
|
||||||
if type(variable.default) in types:
|
if multi is False and variable.type is None:
|
||||||
variable.type = types[type(variable.default)]
|
if type(variable.default) in basic_types:
|
||||||
|
variable.type = basic_types[type(variable.default)]
|
||||||
|
else:
|
||||||
|
# XXX FIXME strange. weird. not good
|
||||||
|
variable.type = "string"
|
||||||
egarette
commented
If variable.type is "number" it will override by "string". Multi value should be supported too (raise if type are different in this case). If variable.type is "number" it will override by "string".
Multi value should be supported too (raise if type are different in this case).
|
|||||||
# 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:
|
||||||
variable.default = True
|
variable.default = True
|
||||||
|
|
|
@ -679,6 +679,7 @@ class ParserVariable:
|
||||||
if not isinstance(filename, list):
|
if not isinstance(filename, list):
|
||||||
filename = [filename]
|
filename = [filename]
|
||||||
variable["xmlfiles"] = filename
|
variable["xmlfiles"] = filename
|
||||||
|
variable["version"] = version
|
||||||
variable_type = self.get_family_or_variable_type(variable)
|
variable_type = self.get_family_or_variable_type(variable)
|
||||||
obj = {
|
obj = {
|
||||||
"symlink": SymLink,
|
"symlink": SymLink,
|
||||||
|
|
|
@ -439,6 +439,7 @@ class Variable(BaseModel):
|
||||||
test: Optional[list] = None
|
test: Optional[list] = None
|
||||||
xmlfiles: List[str] = []
|
xmlfiles: List[str] = []
|
||||||
path: str
|
path: str
|
||||||
|
version: str
|
||||||
# type will be set dynamically in `annotator/value.py`, default is None
|
# type will be set dynamically in `annotator/value.py`, default is None
|
||||||
type: str = None
|
type: str = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue
This line is not correct to me.
Example:
is an invalid dictionary.