# Buggy code
def _draw_collapsed_indicator(
    self, line_number, top_position, block, painter, mouse_hover=False
):
    if line_number in self.folding_regions:
        collapsed = self.folding_status[line_number]
        line_end = self.folding_regions[line_number]
        mouse_over = self._mouse_over_line == line_number
        if not mouse_hover:
            self._draw_fold_indicator(top_position, mouse_over, collapsed, painter)
        if collapsed:
            if mouse_hover:
                self._draw_fold_indicator(top_position, mouse_over, collapsed, painter)
            # check if the block already has a decoration,
            # it might have been folded by the parent
            # editor/document in the case of cloned editor
            for deco in self._block_decos:
                if deco.block == block:
                    # no need to add a deco, just go to the
                    # next block
                    break
            else:
                self._add_fold_decoration(block, line_end)
        elif not mouse_hover:
            for deco in self._block_decos:
                # check if the block decoration has been removed, it
                # might have been unfolded by the parent
                # editor/document in the case of cloned editor
                if deco.block == block:
                    # remove it and
                    self._block_decos.remove(deco)
                    self.editor.decorations.remove(deco)
                    del deco
                    break


# Traceback (KeyError)
File "C:\Users\marco\Anaconda3\lib\site-packages\spyder\plugins\editor\utils\editor.py", line 161, in _exec_requested_job
self._job(*self._args, **self._kwargs)
File "C:\Users\marco\Anaconda3\lib\site-packages\spyder\plugins\editor\panels\codefolding.py", line 471, in _highlight_block
end_line = self.folding_regions[block_line]
KeyError: 155

# Fixed code
def _draw_collapsed_indicator(
    self, line_number, top_position, block, painter, mouse_hover=False
):
    if line_number in self.folding_regions:
        collapsed = self.folding_status[line_number]
        line_end = self.folding_regions[line_number]
        mouse_over = self._mouse_over_line == line_number
        if not mouse_hover:
            self._draw_fold_indicator(top_position, mouse_over, collapsed, painter)
        if collapsed:
            if mouse_hover:
                self._draw_fold_indicator(top_position, mouse_over, collapsed, painter)
            # check if the block already has a decoration,
            # it might have been folded by the parent
            # editor/document in the case of cloned editor
            for deco_line in self._block_decos:
                deco = self._block_decos[deco_line]
                if deco.block == block:
                    # no need to add a deco, just go to the
                    # next block
                    break
            else:
                self._add_fold_decoration(block, line_end)
        elif not mouse_hover:
            for deco_line in list(self._block_decos.keys()):
                deco = self._block_decos[deco_line]
                # check if the block decoration has been removed, it
                # might have been unfolded by the parent
                # editor/document in the case of cloned editor
                if deco.block == block:
                    # remove it and
                    self._block_decos.pop(deco_line)
                    self.editor.decorations.remove(deco)
                    del deco
                    break