Replace this node with a new one in the parent.
(self, new)
| 99 | raise NotImplementedError |
| 100 | |
| 101 | def replace(self, new): |
| 102 | """Replace this node with a new one in the parent.""" |
| 103 | assert self.parent is not None, str(self) |
| 104 | assert new is not None |
| 105 | if not isinstance(new, list): |
| 106 | new = [new] |
| 107 | l_children = [] |
| 108 | found = False |
| 109 | for ch in self.parent.children: |
| 110 | if ch is self: |
| 111 | assert not found, (self.parent.children, self, new) |
| 112 | if new is not None: |
| 113 | l_children.extend(new) |
| 114 | found = True |
| 115 | else: |
| 116 | l_children.append(ch) |
| 117 | assert found, (self.children, self, new) |
| 118 | self.parent.changed() |
| 119 | self.parent.children = l_children |
| 120 | for x in new: |
| 121 | x.parent = self.parent |
| 122 | self.parent = None |
| 123 | |
| 124 | def get_lineno(self): |
| 125 | """Return the line number which generated the invocant node.""" |