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

Function standalone_comment_split

src/black/linegen.py:1456–1487  ·  view source on GitHub ↗

Split standalone comments from the rest of the line.

(
    line: Line, features: Collection[Feature], mode: Mode
)

Source from the content-addressed store, hash-verified

1454
1455@dont_increase_indentation
1456def standalone_comment_split(
1457 line: Line, features: Collection[Feature], mode: Mode
1458) -> Iterator[Line]:
1459 """Split standalone comments from the rest of the line."""
1460 if not line.contains_standalone_comments():
1461 raise CannotSplit("Line does not have any standalone comments")
1462
1463 current_line = Line(
1464 mode=line.mode, depth=line.depth, inside_brackets=line.inside_brackets
1465 )
1466
1467 def append_to_line(leaf: Leaf) -> Iterator[Line]:
1468 """Append `leaf` to current line or to new line if appending impossible."""
1469 nonlocal current_line
1470 try:
1471 current_line.append_safe(leaf, preformatted=True)
1472 except ValueError:
1473 yield current_line
1474
1475 current_line = Line(
1476 line.mode, depth=line.depth, inside_brackets=line.inside_brackets
1477 )
1478 current_line.append(leaf)
1479
1480 for leaf in line.leaves:
1481 yield from append_to_line(leaf)
1482
1483 for comment_after in line.comments_after(leaf):
1484 yield from append_to_line(comment_after)
1485
1486 if current_line:
1487 yield current_line
1488
1489
1490def normalize_invisible_parens(

Callers

nothing calls this directly

Calls 5

LineClass · 0.90
CannotSplitClass · 0.85
append_to_lineFunction · 0.85
comments_afterMethod · 0.80

Tested by

no test coverage detected