Skip to content

Commit 8966c0d

Browse files
samuel-gauthierrjarry
authored andcommitted
schema: fix type extensions
The ext_size field has been removed, we need to use LY_ARRAY_COUNT now. It fixes the following error when calling type.extensions(): > File "/(...)/.venv/src/libyang/libyang/schema.py", line 579, in extensions > for i in range(self.cdata.ext_size): > AttributeError: cdata 'struct lysc_type *' has no field 'ext_size' Signed-off-by: Samuel Gauthier <samuel.gauthier@6wind.com>
1 parent 92c682f commit 8966c0d

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

libyang/schema.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,8 @@ def module(self) -> Module:
576576
return Module(self.context, self.cdata.der.module)
577577

578578
def extensions(self) -> Iterator[ExtensionCompiled]:
579-
for i in range(self.cdata.ext_size):
580-
yield ExtensionCompiled(self.context, self.cdata.ext[i])
581-
if self.cdata.parent:
582-
for i in range(self.cdata.parent.ext_size):
583-
yield ExtensionCompiled(self.context, self.cdata.parent.ext[i])
579+
for extension in ly_array_iter(self.cdata.exts):
580+
yield ExtensionCompiled(self.context, extension)
584581

585582
def get_extension(
586583
self, name: str, prefix: Optional[str] = None, arg_value: Optional[str] = None

tests/test_schema.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,16 @@ def test_leaf_type_union(self):
401401
bases = set(t.basenames())
402402
self.assertEqual(bases, set(["int16", "int32", "uint16", "uint32"]))
403403

404+
def test_leaf_type_extensions(self):
405+
leaf = next(
406+
self.ctx.find_path("/yolo-system:conf/yolo-system:url/yolo-system:proto")
407+
)
408+
t = leaf.type()
409+
ext = t.get_extension(
410+
"type-desc", prefix="omg-extensions", arg_value="<protocol>"
411+
)
412+
self.assertIsInstance(ext, Extension)
413+
404414
def test_leaf_type_enum(self):
405415
leaf = next(
406416
self.ctx.find_path("/yolo-system:conf/yolo-system:url/yolo-system:proto")

tests/yang/omg/omg-extensions.yang

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ module omg-extensions {
1212
"Extend a node to provide a human readable name.";
1313
argument name;
1414
}
15+
16+
extension type-desc {
17+
description
18+
"Extend a type to add a desc.";
19+
argument name;
20+
}
1521
}

tests/yang/yolo/yolo-system.yang

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ module yolo-system {
6565
"An URL.";
6666
key "proto host";
6767
leaf proto {
68-
type types:protocol;
68+
type types:protocol {
69+
ext:type-desc "<protocol>";
70+
}
6971
}
7072
leaf host {
7173
type string;

0 commit comments

Comments
 (0)