Get header nodes for a compound statement that should be preserved inline.
(
body_node: Node, simple_stmt_parent: Node
)
| 615 | |
| 616 | |
| 617 | def _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 | |
| 642 | def _find_closest_previous_sibling(node: LN) -> LN | None: |
no test coverage detected