Skip to content

Commit

Permalink
schema: use ly_array_iter for SLeafList defaults API
Browse files Browse the repository at this point in the history
It is way clearer this way.

Closes: #119
Signed-off-by: Stefan Gula <[email protected]>
Signed-off-by: Samuel Gauthier <[email protected]>
  • Loading branch information
samuel-gauthier committed Aug 2, 2024
1 parent 2fc312b commit e1cefcf
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions libyang/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,15 +1414,12 @@ def type(self) -> Type:
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]
for i in range(arr_length):
val = lib.lyd_value_get_canonical(
self.context.cdata, self.cdata_leaflist.dflts[i]
)
for dflt in ly_array_iter(self.cdata_leaflist.dflts):
val = lib.lyd_value_get_canonical(self.context.cdata, dflt)
if not val:
yield None
val = c2str(val)
val_type = Type(self.context, self.cdata_leaflist.dflts[i].realtype, None)
val_type = Type(self.context, dflt.realtype, None)
if val_type == Type.BOOL:
yield val == "true"
elif val_type in Type.NUM_TYPES:
Expand Down

0 comments on commit e1cefcf

Please sign in to comment.