From 851ea1bc0006927319ac5a9f9d1eba0b7c0bf52c Mon Sep 17 00:00:00 2001 From: Stefan Gula Date: Tue, 28 Nov 2023 14:59:21 +0100 Subject: [PATCH] Fixed defaults function output --- libyang/schema.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libyang/schema.py b/libyang/schema.py index 8a58b13f..1d46fed3 100644 --- a/libyang/schema.py +++ b/libyang/schema.py @@ -1219,7 +1219,7 @@ def __init__(self, context: "libyang.Context", cdata): self.cdata_leaf = ffi.cast("struct lysc_node_leaf *", cdata) self.cdata_leaf_parsed = ffi.cast("struct lysp_node_leaf *", self.cdata_parsed) - def default(self) -> Union[None, bool, int, str]: + def default(self) -> Union[None, bool, int, str, float]: if not self.cdata_leaf.dflt: return None val = lib.lyd_value_get_canonical(self.context.cdata, self.cdata_leaf.dflt) @@ -1231,6 +1231,8 @@ def default(self) -> Union[None, bool, int, str]: return val == "true" if val_type.base() in Type.NUM_TYPES: return int(val) + if val_type.base() == Type.DEC64: + return float(val) return val def units(self) -> Optional[str]: @@ -1278,7 +1280,7 @@ def type(self) -> Type: self.context, self.cdata_leaflist.type, self.cdata_leaflist_parsed.type ) - def defaults(self) -> Iterator[str]: + def defaults(self) -> Iterator[Union[None, bool, int, str, float]]: if self.cdata_leaflist.dflts == ffi.NULL: return arr_length = ffi.cast("uint64_t *", self.cdata_leaflist.dflts)[-1] @@ -1294,6 +1296,8 @@ def defaults(self) -> Iterator[str]: ret = val == "true" elif val_type in Type.NUM_TYPES: ret = int(val) + elif val_type == Type.DEC64: + ret = float(val) yield ret def must_conditions(self) -> Iterator[str]: