From 463b57ea2d42cf203dee9490f1de71d0d2ac0c91 Mon Sep 17 00:00:00 2001 From: gwen Date: Tue, 9 Apr 2024 11:58:33 +0200 Subject: [PATCH] feat: add default inference for basic types --- src/rougail/annotator/value.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/rougail/annotator/value.py b/src/rougail/annotator/value.py index 18fc01251..9f5d595ff 100644 --- a/src/rougail/annotator/value.py +++ b/src/rougail/annotator/value.py @@ -62,6 +62,14 @@ class Annotator(Walk): # pylint: disable=R0903 variable: dict, ) -> None: multi = self.objectspace.multis.get(variable.path, False) + + types = {str: "string", int: "number", bool: "boolean", float: "float"} + + # variable's type inference with a default value with a basic type + if multi is False and variable.type == "string" and type(variable.default) != str: + if type(variable.default) in types: + variable.type = types[type(variable.default)] + # 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