Split standalone comments from the rest of the line.
(
line: Line, features: Collection[Feature], mode: Mode
)
| 1454 | |
| 1455 | @dont_increase_indentation |
| 1456 | def 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 | |
| 1490 | def normalize_invisible_parens( |
nothing calls this directly
no test coverage detected