usort/sorting.py
def find_and_sort_blocks(
        self,
        body: Sequence[cst.BaseStatement],
        module: cst.Module,
        indent: str,
    ) -> Sequence[cst.BaseStatement]:
        """
        Find all sortable blocks in a module, sort them, and return updated module content.
        """
        sorted_body: List[cst.BaseStatement] = list(body)
        blocks = list(self.sortable_blocks(body))

        for block in blocks:
            initial_blank, initial_comment = self.partition_leading_lines(
                block.imports[0].comments.before
            )
            block.imports[0].comments.before = initial_comment
            # Sort the imports first, so that imports from the same module line up, then
            # merge and sort imports/items, then re-sort the final set of imports again
            # in case unsorted items affected overall sorting.
            imports = sorted(block.imports)
            imports = self.merge_and_sort_imports(imports)
            imports = self.fixup_whitespace(initial_blank, imports)
            block.imports = sorted(imports)

        # replace statements in reverse order in case some got merged, which throws off
        # indexes for statements past the merge
        for block in reversed(blocks):
            sorted_body[block.start_idx : block.end_idx] = [
                import_to_node(imp, module, indent, self.config)
                for imp in block.imports
            ]

        return sorted_body

        Find all sortable blocks in a module, sort them, and return updated module content.
        
Find all sortable blocks in a module, sort them, and return updated module content.
Find all sortable blocks in a module sort them and return updated module content .
def find_and_sort_blocks(
        self,
        body: Sequence[cst.BaseStatement],
        module: cst.Module,
        indent: str,
    ) -> Sequence[cst.BaseStatement]:
        sorted_body: List[cst.BaseStatement] = list(body)
        blocks = list(self.sortable_blocks(body))
        for block in blocks:
            initial_blank, initial_comment = self.partition_leading_lines(
                block.imports[0].comments.before
            )
            block.imports[0].comments.before = initial_comment
            imports = sorted(block.imports)
            imports = self.merge_and_sort_imports(imports)
            imports = self.fixup_whitespace(initial_blank, imports)
            block.imports = sorted(imports)
        for block in reversed(blocks):
            sorted_body[block.start_idx : block.end_idx] = [
                import_to_node(imp, module, indent, self.config)
                for imp in block.imports
            ]
        return sorted_body
def find_and_sort_blocks ( self , body : Sequence [ cst . BaseStatement ] , module : cst . Module , indent : str , ) -> Sequence [ cst . BaseStatement ] : sorted_body : List [ cst . BaseStatement ] = list ( body ) blocks = list ( self . sortable_blocks ( body ) ) for block in blocks : initial_blank , initial_comment = self . partition_leading_lines ( block . imports [ 0 ] . comments . before ) block . imports [ 0 ] . comments . before = initial_comment imports = sorted ( block . imports ) imports = self . merge_and_sort_imports ( imports ) imports = self . fixup_whitespace ( initial_blank , imports ) block . imports = sorted ( imports ) for block in reversed ( blocks ) : sorted_body [ block . start_idx : block . end_idx ] = [ import_to_node ( imp , module , indent , self . config ) for imp in block . imports ] return sorted_body
Find all sortable blocks in a module, sort them, and return updated module content.
Find all sortable blocks in a module sort them and return updated module content .
"""
        Find all sortable blocks in a module, sort them, and return updated module content.
        """ # Sort the imports first, so that imports from the same module line up, then # merge and sort imports/items, then re-sort the final set of imports again # in case unsorted items affected overall sorting. # replace statements in reverse order in case some got merged, which throws off # indexes for statements past the merge
self
body
Sequence[cst.BaseStatement]
module
cst.Module
indent
str