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

Code before:

    If it's the body component, the result line is one-indented inside brackets and as
    such has its first leaf's prefix normalized and a trailing comma added when
    expected.
    """
    result = Line(mode=original.mode, depth=original.depth)
    if component is _BracketSplitComponent.body:
        result.inside_brackets = True
        result.depth += 1
        if leaves:
            no_commas = (
                # Ensure a trailing comma for imports and standalone function arguments
                original.is_def
                # Don't add one after any comments or within type annotations
                and opening_bracket.value == "("
                # Don't add one if there's already one there
                and not any(
                    leaf.type == token.COMMA
                    and (
                        Preview.typed_params_trailing_comma not in original.mode
                        or not is_part_of_annotation(leaf)
                    )
                    for leaf in leaves
                )
                # Don't add one inside parenthesized return annotations
                and not get_annotation_type(leaves[0]) == "return"
                # Don't add one inside PEP 604 unions
                and not (
                    leaves[0].parent
                    and leaves[0].parent.next_sibling
                    and leaves[0].parent.next_sibling.type == token.VBAR
                )
            )

            if original.is_import or no_commas:
                for i in range(len(leaves) - 1, -1, -1):
                    if leaves[i].type == STANDALONE_COMMENT:
                        continue

                    if leaves[i].type != token.COMMA:
                        new_comma = Leaf(token.COMMA, ",")
                        leaves.insert(i + 1, new_comma)
                    break

    leaves_to_track: Set[LeafID] = set()
    if component is _BracketSplitComponent.head:
        leaves_to_track = get_leaves_inside_matching_brackets(leaves)
    # Populate the line
    for leaf in leaves:
        result.append(
            leaf,

Review comment (suggestion):
```suggestion
                and get_annotation_type(leaves[0]) != "return"
```

Code after:
    original: Line,
    opening_bracket: Leaf,
    *,
    component: _BracketSplitComponent,
) -> Line:
    """Return a new line with given `leaves` and respective comments from `original`.

    If it's the head component, brackets will be tracked so trailing commas are
    respected.

    If it's the body component, the result line is one-indented inside brackets and as
    such has its first leaf's prefix normalized and a trailing comma added when
    expected.
    """
    result = Line(mode=original.mode, depth=original.depth)
    if component is _BracketSplitComponent.body:
        result.inside_brackets = True
        result.depth += 1
        if leaves:
            no_commas = (
                # Ensure a trailing comma for imports and standalone function arguments
                original.is_def
                # Don't add one after any comments or within type annotations
                and opening_bracket.value == "("
                # Don't add one if there's already one there
                and not any(
                    leaf.type == token.COMMA
                    and (
                        Preview.typed_params_trailing_comma not in original.mode
                        or not is_part_of_annotation(leaf)
                    )
                    for leaf in leaves
                )
                # Don't add one inside parenthesized return annotations
                and get_annotation_type(leaves[0]) != "return"
                # Don't add one inside PEP 604 unions
                and not (
                    leaves[0].parent
                    and leaves[0].parent.next_sibling
                    and leaves[0].parent.next_sibling.type == token.VBAR
                )
            )

            if original.is_import or no_commas:
                for i in range(len(leaves) - 1, -1, -1):
                    if leaves[i].type == STANDALONE_COMMENT:
                        continue

                    if leaves[i].type != token.COMMA:
                        new_comma = Leaf(token.COMMA, ",")
                        leaves.insert(i + 1, new_comma)