Skip to content

Commit

Permalink
Fixed defaults function output
Browse files Browse the repository at this point in the history
  • Loading branch information
steweg committed Dec 7, 2023
1 parent 8edf829 commit b044681
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions libyang/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,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)
Expand All @@ -1226,6 +1226,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]:
Expand Down Expand Up @@ -1273,7 +1275,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]
Expand All @@ -1289,6 +1291,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]:
Expand Down

0 comments on commit b044681

Please sign in to comment.