feat: add default inference behavior for basic types #13
1 changed files with 8 additions and 0 deletions
|
@ -62,6 +62,14 @@ 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)
|
||||||
|
|
||||||
|
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)]
|
||||||
egarette
commented
Not only 1.1, should be "else:" Not only 1.1, should be "else:"
|
|||||||
|
|
||||||
# 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
|
||||||
|
|
Loading…
Reference in a new issue
This line is not correct to me.
Example:
is an invalid dictionary.