From e1cefcf64d5374f4c0bcc769e46bfe8758b317bb Mon Sep 17 00:00:00 2001 From: Samuel Gauthier Date: Fri, 2 Aug 2024 15:42:13 +0200 Subject: [PATCH] schema: use ly_array_iter for SLeafList defaults API It is way clearer this way. Closes: https://github.com/CESNET/libyang-python/pull/119 Signed-off-by: Stefan Gula Signed-off-by: Samuel Gauthier --- libyang/schema.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libyang/schema.py b/libyang/schema.py index 7c79b86..539af88 100644 --- a/libyang/schema.py +++ b/libyang/schema.py @@ -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: