def import_comments_from_node()

in usort/translate.py [0:0]


def import_comments_from_node(node: cst.SimpleStatementLine) -> ImportComments:
    comments = ImportComments()

    assert len(node.body) == 1
    assert isinstance(node.body[0], (cst.Import, cst.ImportFrom))
    imp: Union[cst.Import, cst.ImportFrom] = node.body[0]

    # # THIS PART
    # import foo
    #
    # # THIS PART
    # from foo import bar
    for line in node.leading_lines:
        if line.comment:
            comments.before.append(line.comment.value)
        else:
            comments.before.append("")

    if isinstance(imp, cst.ImportFrom):
        if imp.lpar:
            if isinstance(imp.lpar.whitespace_after, cst.ParenthesizedWhitespace):
                ws = imp.lpar.whitespace_after

                # from foo import (  # THIS PART
                #     bar,
                # )
                if ws.first_line.comment:
                    comments.first_inline.extend(
                        split_inline_comment(ws.first_line.comment.value)
                    )

                # from foo import (
                #     # THIS PART
                #     bar,
                # )
                comments.initial.extend(
                    line.comment.value for line in ws.empty_lines if line.comment
                )

            assert imp.rpar is not None
            if isinstance(imp.rpar.whitespace_before, cst.ParenthesizedWhitespace):
                comments.final.extend(
                    line.comment.value
                    for line in imp.rpar.whitespace_before.empty_lines
                    if line.comment
                )

                if imp.rpar.whitespace_before.first_line.comment:
                    comments.inline.extend(
                        split_inline_comment(
                            imp.rpar.whitespace_before.first_line.comment.value
                        )
                    )

            # from foo import (
            #     bar,
            # )  # THIS PART
            if node.trailing_whitespace and node.trailing_whitespace.comment:
                comments.last_inline.extend(
                    split_inline_comment(node.trailing_whitespace.comment.value)
                )

        # from foo import bar  # THIS PART
        elif node.trailing_whitespace and node.trailing_whitespace.comment:
            comments.first_inline.extend(
                split_inline_comment(node.trailing_whitespace.comment.value)
            )

    # import foo  # THIS PART
    elif isinstance(imp, cst.Import):
        if node.trailing_whitespace and node.trailing_whitespace.comment:
            comments.first_inline.extend(
                split_inline_comment(node.trailing_whitespace.comment.value)
            )

    else:
        raise TypeError

    return comments