diff --git a/libyang/schema.py b/libyang/schema.py index deec466d..c92758ba 100644 --- a/libyang/schema.py +++ b/libyang/schema.py @@ -1364,18 +1364,15 @@ 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) - if val_type == Type.BOOL: + val_type = Type(self.context, dflt.realtype, None) + if val_type.base() == Type.BOOL: yield val == "true" - elif val_type in Type.NUM_TYPES: + elif val_type.base() in Type.NUM_TYPES: yield int(val) elif val_type.base() == Type.DEC64: yield float(val) diff --git a/tests/test_schema.py b/tests/test_schema.py index 64a8e30e..506fda00 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -575,6 +575,12 @@ def test_leaflist_defaults(self): leaflist = next(self.ctx.find_path("/yolo-nodetypes:conf/ratios")) for d in leaflist.defaults(): self.assertIsInstance(d, float) + leaflist = next(self.ctx.find_path("/yolo-nodetypes:conf/bools")) + for d in leaflist.defaults(): + self.assertIsInstance(d, bool) + leaflist = next(self.ctx.find_path("/yolo-nodetypes:conf/integers")) + for d in leaflist.defaults(): + self.assertIsInstance(d, int) def test_leaf_list_min_max(self): leaflist1 = next(self.ctx.find_path("/yolo-nodetypes:conf/leaf-list1")) diff --git a/tests/yang/yolo/yolo-nodetypes.yang b/tests/yang/yolo/yolo-nodetypes.yang index a456ae1d..7e4c8648 100644 --- a/tests/yang/yolo/yolo-nodetypes.yang +++ b/tests/yang/yolo/yolo-nodetypes.yang @@ -44,6 +44,17 @@ module yolo-nodetypes { default 2.6; } + leaf-list bools { + type boolean; + default true; + } + + leaf-list integers { + type uint32; + default 10; + default 20; + } + list list1 { key leaf1; unique "leaf2 leaf3";