Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion libyang/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down