Repository: psf/black
File: src/black/linegen.py (Python)

Code before:
                # A [ at index 2 means this is a type param, so start
                # tracking the depth
                depth += 1
            elif depth > 0:
                if leaf.type == token.LSQB:
                    depth += 1
                elif leaf.type == token.RSQB:
                    depth -= 1
            if (
                current_leaves is body_leaves
                and leaf.type in CLOSING_BRACKETS
                and leaf.opening_bracket is matching_bracket
                and isinstance(matching_bracket, Leaf)
                # If the code is still on LPAR and we are inside a type
                # param, ignore the match since this is searching
                # for the function arguments
                and not (leaf_type == token.LPAR and depth > 0)
            ):
                ensure_visible(leaf)
                ensure_visible(matching_bracket)
                current_leaves = tail_leaves if body_leaves else head_leaves
            current_leaves.append(leaf)
            if current_leaves is head_leaves:
                if leaf.type == leaf_type and (
                    Preview.fix_type_expansion_split
                    and not (leaf_type == token.LPAR and depth > 0)
                ):
                    matching_bracket = leaf
                    current_leaves = body_leaves
        if matching_bracket and tail_leaves:
            break
    if not matching_bracket or not tail_leaves:
        raise CannotSplit("No brackets found")

    head = bracket_split_build_line(
        head_leaves, line, matching_bracket, component=_BracketSplitComponent.head
    )
    body = bracket_split_build_line(
        body_leaves, line, matching_bracket, component=_BracketSplitComponent.body
    )
    tail = bracket_split_build_line(
        tail_leaves, line, matching_bracket, component=_BracketSplitComponent.tail
    )
    bracket_split_succeeded_or_raise(head, body, tail)
    for result in (head, body, tail):
        if result:
            yield result


def right_hand_split(
    line: Line,

Review comment (suggestion):
```suggestion
                    Preview.fix_type_expansion_split not in mode
                    or not (leaf_type == token.LPAR and depth > 0)
```
That should be it, looks like the function already takes `mode` as a parameter, so we can just use it.

Code after:
                # A [ at index 2 means this is a type param, so start
                # tracking the depth
                depth += 1
            elif depth > 0:
                if leaf.type == token.LSQB:
                    depth += 1
                elif leaf.type == token.RSQB:
                    depth -= 1
            if (
                current_leaves is body_leaves
                and leaf.type in CLOSING_BRACKETS
                and leaf.opening_bracket is matching_bracket
                and isinstance(matching_bracket, Leaf)
                # If the code is still on LPAR and we are inside a type
                # param, ignore the match since this is searching
                # for the function arguments
                and not (leaf_type == token.LPAR and depth > 0)
            ):
                ensure_visible(leaf)
                ensure_visible(matching_bracket)
                current_leaves = tail_leaves if body_leaves else head_leaves
            current_leaves.append(leaf)
            if current_leaves is head_leaves:
                if leaf.type == leaf_type and (
                    Preview.fix_type_expansion_split not in mode
                    or not (leaf_type == token.LPAR and depth > 0)
                ):
                    matching_bracket = leaf
                    current_leaves = body_leaves
        if matching_bracket and tail_leaves:
            break
    if not matching_bracket or not tail_leaves:
        raise CannotSplit("No brackets found")

    head = bracket_split_build_line(
        head_leaves, line, matching_bracket, component=_BracketSplitComponent.head
    )
    body = bracket_split_build_line(
        body_leaves, line, matching_bracket, component=_BracketSplitComponent.body
    )
    tail = bracket_split_build_line(
        tail_leaves, line, matching_bracket, component=_BracketSplitComponent.tail
    )
    bracket_split_succeeded_or_raise(head, body, tail)
    for result in (head, body, tail):
        if result:
            yield result


def right_hand_split(
    line: Line,