# Buggy code
def remove_node(self, node):
    for child in self.children[node.index + 1 :]:
        child.index -= 1

    self.children.pop(node.index)
    for idx, next_idx in zip(self.children, self.children[1:]):
        assert idx.index < next_idx.index


# Traceback (IndexError)
--- Logging error ---
Traceback (most recent call last):
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1927, in update_and_merge_folding
current_tree, root = merge_folding(
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 177, in merge_folding
deleted_entry_i.delete()
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 39, in delete
self.parent.remove_node(self)
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 57, in remove_node
self.children.pop(node.index)
IndexError: pop index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 1081, in emit
msg = self.format(record)
File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 925, in format
return fmt.format(record)
File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 664, in format
record.message = record.getMessage()
File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 369, in getMessage
msg = msg % self.args
ValueError: incomplete format
Call stack:
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1938, in update_and_merge_folding
self.log_lsp_handle_errors("Error when processing folding")
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1137, in log_lsp_handle_errors
logger.error('%', 1, stack_info=True)
Message: '%'
Arguments: (1,)
--- Logging error ---
Traceback (most recent call last):
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1927, in update_and_merge_folding
current_tree, root = merge_folding(
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 169, in merge_folding
deleted_entry_i.delete()
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 39, in delete
self.parent.remove_node(self)
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 57, in remove_node
self.children.pop(node.index)
IndexError: pop index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 1081, in emit
msg = self.format(record)
File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 925, in format
return fmt.format(record)
File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 664, in format
record.message = record.getMessage()
File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 369, in getMessage
msg = msg % self.args
ValueError: incomplete format
Call stack:
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1938, in update_and_merge_folding
self.log_lsp_handle_errors("Error when processing folding")
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1137, in log_lsp_handle_errors
logger.error('%', 1, stack_info=True)
Message: '%'
Arguments: (1,)
--- Logging error ---
Traceback (most recent call last):
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1927, in update_and_merge_folding
current_tree, root = merge_folding(
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 169, in merge_folding
deleted_entry_i.delete()
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 39, in delete
self.parent.remove_node(self)
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 57, in remove_node
self.children.pop(node.index)
IndexError: pop index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 1081, in emit
msg = self.format(record)
File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 925, in format
return fmt.format(record)
File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 664, in format
record.message = record.getMessage()
File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 369, in getMessage
msg = msg % self.args
ValueError: incomplete format
Call stack:
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1938, in update_and_merge_folding
self.log_lsp_handle_errors("Error when processing folding")
File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1137, in log_lsp_handle_errors
logger.error('%', 1, stack_info=True)
Message: '%'
Arguments: (1,)

# Fixed code
def remove_node(self, node):
    for child in self.children[node.index + 1 :]:
        child.index -= 1

    try:
        self.children.pop(node.index)
    except IndexError:
        pass
    for idx, next_idx in zip(self.children, self.children[1:]):
        assert idx.index < next_idx.index