usort/sorting.py
def split_inplace(self, block: SortableBlock, overlap: Set[str]) -> SortableBlock:
        """
        Split an existing block into two blocks after the last shadowed import.

        Pre-sorts the block of imports, then finds the last import with shadowed names, and
        splits after that import. Returns a new block containing all imports after the split
        point, or empty otherwise.
        """
        # best-effort pre-sorting before we split
        for imp in block.imports:
            imp.items.sort()
        block.imports.sort()

        # find index of last shadowed import, starting from the end of the block's imports
        idx = len(block.imports)
        while idx > 0:
            idx -= 1
            imp = block.imports[idx]
            if any(item.fullname in overlap for item in imp.items):
                break

        count = idx + 1
        if count >= len(block.imports):
            # shadowed import is the last import in the block, so we can't split anything.
            # return a new, empty block following pattern from sortable_blocks()
            new = SortableBlock(block.end_idx, block.end_idx + 1)

        else:
            # Split the existing block after the shadowed import, creating a new block that
            # starts after the shadowed import, update the old block's end index, and then
            # move all the imports after that to the new block
            new = SortableBlock(block.start_idx + count, block.end_idx)
            block.end_idx = block.start_idx + count

            new.imports = block.imports[count:]
            block.imports[count:] = []

            # move imported names metadata
            for imp in new.imports:
                for key in list(imp.imported_names):
                    new.imported_names[key] = block.imported_names.pop(key)

        return new

        Split an existing block into two blocks after the last shadowed import.

        Pre-sorts the block of imports, then finds the last import with shadowed names, and
        splits after that import. Returns a new block containing all imports after the split
        point, or empty otherwise.
        
Split an existing block into two blocks after the last shadowed import.
Pre-sorts the block of imports, then finds the last import with shadowed names, and
splits after that import. Returns a new block containing all imports after the split
point, or empty otherwise.
Split an existing block into two blocks after the last shadowed import . Pre - sorts the block of imports then finds the last import with shadowed names and splits after that import . Returns a new block containing all imports after the split point or empty otherwise .
def split_inplace(self, block: SortableBlock, overlap: Set[str]) -> SortableBlock:
        for imp in block.imports:
            imp.items.sort()
        block.imports.sort()
        idx = len(block.imports)
        while idx > 0:
            idx -= 1
            imp = block.imports[idx]
            if any(item.fullname in overlap for item in imp.items):
                break
        count = idx + 1
        if count >= len(block.imports):
            new = SortableBlock(block.end_idx, block.end_idx + 1)
        else:
            new = SortableBlock(block.start_idx + count, block.end_idx)
            block.end_idx = block.start_idx + count
            new.imports = block.imports[count:]
            block.imports[count:] = []
            for imp in new.imports:
                for key in list(imp.imported_names):
                    new.imported_names[key] = block.imported_names.pop(key)
        return new
def split_inplace ( self , block : SortableBlock , overlap : Set [ str ] ) -> SortableBlock : for imp in block . imports : imp . items . sort ( ) block . imports . sort ( ) idx = len ( block . imports ) while idx > 0 : idx -= 1 imp = block . imports [ idx ] if any ( item . fullname in overlap for item in imp . items ) : break count = idx + 1 if count >= len ( block . imports ) : new = SortableBlock ( block . end_idx , block . end_idx + 1 ) else : new = SortableBlock ( block . start_idx + count , block . end_idx ) block . end_idx = block . start_idx + count new . imports = block . imports [ count : ] block . imports [ count : ] = [ ] for imp in new . imports : for key in list ( imp . imported_names ) : new . imported_names [ key ] = block . imported_names . pop ( key ) return new
Split an existing block into two blocks after the last shadowed import.
Split an existing block into two blocks after the last shadowed import .
"""
        Split an existing block into two blocks after the last shadowed import.

        Pre-sorts the block of imports, then finds the last import with shadowed names, and
        splits after that import. Returns a new block containing all imports after the split
        point, or empty otherwise.
        """ # best-effort pre-sorting before we split # find index of last shadowed import, starting from the end of the block's imports # shadowed import is the last import in the block, so we can't split anything. # return a new, empty block following pattern from sortable_blocks() # Split the existing block after the shadowed import, creating a new block that # starts after the shadowed import, update the old block's end index, and then # move all the imports after that to the new block # move imported names metadata
self
block
SortableBlock
overlap
Set[str]