MCPcopy
hub / github.com/psf/black / append_leaves

Function append_leaves

src/black/lines.py:1218–1239  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

1216
1217
1218def 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
1242def is_line_short_enough(line: Line, *, mode: Mode, line_str: str = "") -> bool:

Callers 6

run_transformerFunction · 0.90
_merge_string_groupMethod · 0.90
do_transformMethod · 0.90
do_transformMethod · 0.90

Calls 4

LeafClass · 0.90
replace_childFunction · 0.90
comments_afterMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected