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

Function _get_compound_statement_header

src/black/comments.py:617–639  ·  view source on GitHub ↗

Get header nodes for a compound statement that should be preserved inline.

(
    body_node: Node, simple_stmt_parent: Node
)

Source from the content-addressed store, hash-verified

615
616
617def _get_compound_statement_header(
618 body_node: Node, simple_stmt_parent: Node
619) -> list[LN]:
620 """Get header nodes for a compound statement that should be preserved inline."""
621 if not _should_keep_compound_statement_inline(body_node, simple_stmt_parent):
622 return []
623
624 # Get the compound statement (parent of body)
625 compound_stmt = body_node.parent
626 if compound_stmt is None or compound_stmt.type not in _COMPOUND_STATEMENTS:
627 return []
628
629 # Collect all header leaves before the body
630 header_leaves: list[LN] = []
631 for child in compound_stmt.children:
632 if child is body_node:
633 break
634 if isinstance(child, Leaf):
635 if child.type not in (token.NEWLINE, token.INDENT):
636 header_leaves.append(child)
637 else:
638 header_leaves.extend(child.leaves())
639 return header_leaves
640
641
642def _find_closest_previous_sibling(node: LN) -> LN | None:

Callers 1

Calls 3

appendMethod · 0.45
leavesMethod · 0.45

Tested by

no test coverage detected