def next_sibling(self):
        if self.parent:
            nodes = self.parent.children
            index = nodes.index(self)
            sibling = nodes[index + 1] if index < len(nodes) - 1 else None
        else:
            nodes = self.tree.nodes
            index = nodes.index(self)
            sibling = (
                next((n for n in nodes[index + 1:] if n.level == self.level), None)
                if index < len(nodes) - 1 else None
            )
        return sibling