usort/sorting.py
def fixup_whitespace(
        self, initial_blank: Sequence[str], imports: List[SortableImport]
    ) -> List[SortableImport]:
        """
        Normalize whitespace/comments on a block of imports before transforming back to CST.
        """
        cur_category = None
        # TODO if they've already been reshuffled, there may have been a blank
        # (separator) line between a non-block and the first import, that's now in
        # the middle.
        for imp in imports:
            _old_blanks, old_comments = self.partition_leading_lines(
                imp.comments.before
            )

            if cur_category is None:
                blanks = initial_blank
            elif imp.sort_key.category_index != cur_category:
                blanks = ("",)
            else:
                blanks = _old_blanks[:1]

            imp.comments.before = [*blanks, *old_comments]

            cur_category = imp.sort_key.category_index
        return imports

        Normalize whitespace/comments on a block of imports before transforming back to CST.
        
Normalize whitespace/comments on a block of imports before transforming back to CST.
Normalize whitespace / comments on a block of imports before transforming back to CST .
def fixup_whitespace(
        self, initial_blank: Sequence[str], imports: List[SortableImport]
    ) -> List[SortableImport]:
        cur_category = None
        for imp in imports:
            _old_blanks, old_comments = self.partition_leading_lines(
                imp.comments.before
            )
            if cur_category is None:
                blanks = initial_blank
            elif imp.sort_key.category_index != cur_category:
                blanks = ("",)
            else:
                blanks = _old_blanks[:1]
            imp.comments.before = [*blanks, *old_comments]
            cur_category = imp.sort_key.category_index
        return imports
def fixup_whitespace ( self , initial_blank : Sequence [ str ] , imports : List [ SortableImport ] ) -> List [ SortableImport ] : cur_category = None for imp in imports : _old_blanks , old_comments = self . partition_leading_lines ( imp . comments . before ) if cur_category is None : blanks = initial_blank elif imp . sort_key . category_index != cur_category : blanks = ( "" , ) else : blanks = _old_blanks [ : 1 ] imp . comments . before = [ * blanks , * old_comments ] cur_category = imp . sort_key . category_index return imports
Normalize whitespace/comments on a block of imports before transforming back to CST.
Normalize whitespace / comments on a block of imports before transforming back to CST .
"""
        Normalize whitespace/comments on a block of imports before transforming back to CST.
        """ # TODO if they've already been reshuffled, there may have been a blank # (separator) line between a non-block and the first import, that's now in # the middle.
self
initial_blank
Sequence[str]
imports
List[SortableImport]