(self, parent: Self | None, child_name: str | None = None)
| 139 | self._post_detach(parent) |
| 140 | |
| 141 | def _attach(self, parent: Self | None, child_name: str | None = None) -> None: |
| 142 | if parent is not None: |
| 143 | if child_name is None: |
| 144 | raise ValueError( |
| 145 | "To directly set parent, child needs a name, but child is unnamed" |
| 146 | ) |
| 147 | |
| 148 | self._pre_attach(parent, child_name) |
| 149 | parentchildren = parent._children |
| 150 | assert not any(child is self for child in parentchildren), ( |
| 151 | "Tree is corrupt." |
| 152 | ) |
| 153 | parentchildren[child_name] = self |
| 154 | self._parent = parent |
| 155 | self._post_attach(parent, child_name) |
| 156 | else: |
| 157 | self._parent = None |
| 158 | |
| 159 | def orphan(self) -> None: |
| 160 | """Detach this node from its parent.""" |
no test coverage detected