Append leaves (taken from @old_line) to @new_line, making sure to fix the underlying Node structure where appropriate. All of the leaves in @leaves are duplicated. The duplicates are then appended to @new_line and used to replace their originals in the underlying Node structure
(
new_line: Line, old_line: Line, leaves: list[Leaf], preformatted: bool = False
)
| 1216 | |
| 1217 | |
| 1218 | def append_leaves( |
| 1219 | new_line: Line, old_line: Line, leaves: list[Leaf], preformatted: bool = False |
| 1220 | ) -> None: |
| 1221 | """ |
| 1222 | Append leaves (taken from @old_line) to @new_line, making sure to fix the |
| 1223 | underlying Node structure where appropriate. |
| 1224 | |
| 1225 | All of the leaves in @leaves are duplicated. The duplicates are then |
| 1226 | appended to @new_line and used to replace their originals in the underlying |
| 1227 | Node structure. Any comments attached to the old leaves are reattached to |
| 1228 | the new leaves. |
| 1229 | |
| 1230 | Pre-conditions: |
| 1231 | set(@leaves) is a subset of set(@old_line.leaves). |
| 1232 | """ |
| 1233 | for old_leaf in leaves: |
| 1234 | new_leaf = Leaf(old_leaf.type, old_leaf.value) |
| 1235 | replace_child(old_leaf, new_leaf) |
| 1236 | new_line.append(new_leaf, preformatted=preformatted) |
| 1237 | |
| 1238 | for comment_leaf in old_line.comments_after(old_leaf): |
| 1239 | new_line.append(comment_leaf, preformatted=True) |
| 1240 | |
| 1241 | |
| 1242 | def is_line_short_enough(line: Line, *, mode: Mode, line_str: str = "") -> bool: |
no test coverage detected