From ea42b9e8c3b6393b618dec33714cc489e06f1bd8 Mon Sep 17 00:00:00 2001 From: Stefan Gula Date: Mon, 22 Sep 2025 00:52:49 +0200 Subject: [PATCH] schema: adds ability to get various outputs as extension parent_node This patch adds ability to get also PRefine, PType and PEnum as a valid output using extension parent_node function Signed-off-by: Stefan Gula --- libyang/schema.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libyang/schema.py b/libyang/schema.py index 3f3bd4d..8654f24 100644 --- a/libyang/schema.py +++ b/libyang/schema.py @@ -423,10 +423,21 @@ def name(self) -> str: def module(self) -> Module: return self._module_from_parsed() - def parent_node(self) -> Optional[Union["PNode", "PIdentity"]]: + def parent_node( + self, + ) -> Optional[Union["PNode", "PIdentity", "PRefine", "PType", "PEnum"]]: if self.cdata.parent_stmt == lib.LY_STMT_IDENTITY: cdata = ffi.cast("struct lysp_ident *", self.cdata.parent) return PIdentity(self.context, cdata, self.module_parent) + if self.cdata.parent_stmt == lib.LY_STMT_REFINE: + cdata = ffi.cast("struct lysp_refine *", self.cdata.parent) + return PRefine(self.context, cdata, self.module_parent) + if self.cdata.parent_stmt == lib.LY_STMT_TYPE: + cdata = ffi.cast("struct lysp_type *", self.cdata.parent) + return PType(self.context, cdata, self.module_parent) + if self.cdata.parent_stmt == lib.LY_STMT_ENUM: + cdata = ffi.cast("struct lysp_type_enum *", self.cdata.parent) + return PEnum(self.context, cdata, self.module_parent) if bool(self.cdata.parent_stmt & lib.LY_STMT_NODE_MASK): try: return PNode.new(self.context, self.cdata.parent, self.module_parent)