Insert a node as a child of this node a specific index. :param index: The index at which to insert the new child. :param data: The data to insert into the Node as a child. This data will be converted into a Node object. :param children: The data for the children
(self, index: int, data: object, children: object = None)
| 115 | self._source.notify("change", item=node) |
| 116 | |
| 117 | def insert(self, index: int, data: object, children: object = None) -> Node[T]: |
| 118 | """Insert a node as a child of this node a specific index. |
| 119 | |
| 120 | :param index: The index at which to insert the new child. |
| 121 | :param data: The data to insert into the Node as a child. This data will be |
| 122 | converted into a Node object. |
| 123 | :param children: The data for the children of the new child node. |
| 124 | :returns: The new added child Node object. |
| 125 | """ |
| 126 | if self._children is None: |
| 127 | self._children = [] |
| 128 | |
| 129 | if index < 0: |
| 130 | index = max(len(self) + index, 0) |
| 131 | else: |
| 132 | index = min(len(self), index) |
| 133 | |
| 134 | node = self._source._create_node(parent=self, data=data, children=children) |
| 135 | self._children.insert(index, node) |
| 136 | self._source.notify("insert", parent=self, index=index, item=node) |
| 137 | return node |
| 138 | |
| 139 | def append(self, data: object, children: object = None) -> Node[T]: |
| 140 | """Append a node to the end of the list of children of this node. |
no test coverage detected