gurudesh/pytracebugs huggingface dataset:
# Buggy code
def get_config_fpath_from_version(self, version=None):
    """
    Override method.

    Return the configuration path for given version.

    If no version is provided, it returns the current file path.
    """
    if version is None:
        fpath = self.get_config_fpath()
    elif check_version(version, "51.0.0", "<"):
        fpath = osp.join(get_conf_path(), "spyder.ini")
    else:
        fpath = self.get_config_fpath()

    return fpath


# Traceback (AttributeError)
File "C:\Anaconda3\lib\site-packages\spyder\preferences\shortcuts.py", line 850, in reset_to_default
CONF.reset_shortcuts()
File "C:\Anaconda3\lib\site-packages\spyder\config\manager.py", line 322, in reset_shortcuts
plugin_config.reset_to_defaults(section='shortcuts')
AttributeError: 'str' object has no attribute 'reset_to_defaults'

# Fixed code
def get_config_fpath_from_version(self, version=None):
    """
    Override method.

    Return the configuration path for given version.

    If no version is provided, it returns the current file path.
    """
    if version is None or self._external_plugin:
        fpath = self.get_config_fpath()
    elif check_version(version, "51.0.0", "<"):
        fpath = osp.join(get_conf_path(), "spyder.ini")
    else:
        fpath = self.get_config_fpath()

    return fpath
# Buggy code
def apply_configuration_patches(self, old_version=None):
    """
    Override method.

    Apply any patch to configuration values on version changes.
    """
    self._update_defaults(self.defaults, old_version)

    if old_version and check_version(old_version, "44.1.0", "<"):
        run_lines = to_text_string(self.get("ipython_console", "startup/run_lines"))
        if run_lines is not NoDefault:
            run_lines = run_lines.replace(",", "; ")
            self.set("ipython_console", "startup/run_lines", run_lines)


# Traceback (AttributeError)
File "C:\Anaconda3\lib\site-packages\spyder\preferences\shortcuts.py", line 850, in reset_to_default
CONF.reset_shortcuts()
File "C:\Anaconda3\lib\site-packages\spyder\config\manager.py", line 322, in reset_shortcuts
plugin_config.reset_to_defaults(section='shortcuts')
AttributeError: 'str' object has no attribute 'reset_to_defaults'

# Fixed code
def apply_configuration_patches(self, old_version=None):
    """
    Override method.

    Apply any patch to configuration values on version changes.
    """
    self._update_defaults(self.defaults, old_version)

    if self._external_plugin:
        return
    if old_version and check_version(old_version, "44.1.0", "<"):
        run_lines = to_text_string(self.get("ipython_console", "startup/run_lines"))
        if run_lines is not NoDefault:
            run_lines = run_lines.replace(",", "; ")
            self.set("ipython_console", "startup/run_lines", run_lines)
# Buggy code
def _check_name_map(self, name_map):
    """Check `name_map` follows the correct format."""
    # Check section option paris are not repeated
    sections_options = []
    for _, sec_opts in name_map.items():
        for section, options in sec_opts:
            for option in options:
                sec_opt = (section, option)
                if sec_opt not in sections_options:
                    sections_options.append(sec_opt)
                else:
                    raise ValueError(
                        'Different files are holding the same section/option: "{}/{}"!'.format(
                            section, option
                        )
                    )
    return name_map


# Traceback (AttributeError)
File "C:\Anaconda3\lib\site-packages\spyder\preferences\shortcuts.py", line 850, in reset_to_default
CONF.reset_shortcuts()
File "C:\Anaconda3\lib\site-packages\spyder\config\manager.py", line 322, in reset_shortcuts
plugin_config.reset_to_defaults(section='shortcuts')
AttributeError: 'str' object has no attribute 'reset_to_defaults'

# Fixed code
def _check_name_map(self, name_map):
    """Check `name_map` follows the correct format."""
    # Check section option paris are not repeated
    sections_options = []
    for _, sec_opts in name_map.items():
        for section, options in sec_opts:
            for option in options:
                sec_opt = (section, option)
                if sec_opt not in sections_options:
                    sections_options.append(sec_opt)
                else:
                    error_msg = (
                        "Different files are holding the same "
                        'section/option: "{}/{}"!'.format(section, option)
                    )
                    raise ValueError(error_msg)
    return name_map
# Buggy code
def cleanup(self):
    """Remove .ini files associated to configurations."""
    for config in self._configs_map:
        os.remove(config.get_config_fpath())


# Traceback (AttributeError)
File "C:\Anaconda3\lib\site-packages\spyder\preferences\shortcuts.py", line 850, in reset_to_default
CONF.reset_shortcuts()
File "C:\Anaconda3\lib\site-packages\spyder\config\manager.py", line 322, in reset_shortcuts
plugin_config.reset_to_defaults(section='shortcuts')
AttributeError: 'str' object has no attribute 'reset_to_defaults'

# Fixed code
def cleanup(self):
    """Remove .ini files associated to configurations."""
    for _, config in self._configs_map.items():
        os.remove(config.get_config_fpath())
# Buggy code
def iter_shortcuts(self):
    """Iterate over keyboard shortcuts."""
    for context_name, keystr in self._user_config.items("shortcuts"):
        context, name = context_name.split("/", 1)
        yield context, name, keystr

    for p_section, (p_class, p_config) in self._plugin_configs.items():
        items = p_config.items("shortcuts")
        if items:
            for context_name, keystr in items:
                context, name = context_name.split("/", 1)
                yield context, name, keystr


# Traceback (AttributeError)
File "C:\Anaconda3\lib\site-packages\spyder\preferences\shortcuts.py", line 850, in reset_to_default
CONF.reset_shortcuts()
File "C:\Anaconda3\lib\site-packages\spyder\config\manager.py", line 322, in reset_shortcuts
plugin_config.reset_to_defaults(section='shortcuts')
AttributeError: 'str' object has no attribute 'reset_to_defaults'

# Fixed code
def iter_shortcuts(self):
    """Iterate over keyboard shortcuts."""
    for context_name, keystr in self._user_config.items("shortcuts"):
        context, name = context_name.split("/", 1)
        yield context, name, keystr

    for _, (_, plugin_config) in self._plugin_configs.items():
        items = plugin_config.items("shortcuts")
        if items:
            for context_name, keystr in items:
                context, name = context_name.split("/", 1)
                yield context, name, keystr
# Buggy code
def reset_shortcuts(self):
    """Reset keyboard shortcuts to default values."""
    self._user_config.reset_to_defaults(section="shortcuts")
    for plugin_config in self._plugin_configs:
        # TODO: check if the section exists?
        plugin_config.reset_to_defaults(section="shortcuts")


# Traceback (AttributeError)
File "C:\Anaconda3\lib\site-packages\spyder\preferences\shortcuts.py", line 850, in reset_to_default
CONF.reset_shortcuts()
File "C:\Anaconda3\lib\site-packages\spyder\config\manager.py", line 322, in reset_shortcuts
plugin_config.reset_to_defaults(section='shortcuts')
AttributeError: 'str' object has no attribute 'reset_to_defaults'

# Fixed code
def reset_shortcuts(self):
    """Reset keyboard shortcuts to default values."""
    self._user_config.reset_to_defaults(section="shortcuts")
    for _, (_, plugin_config) in self._plugin_configs.items():
        # TODO: check if the section exists?
        plugin_config.reset_to_defaults(section="shortcuts")
# Buggy code
def reset_to_default(self):
    """Reset to default values of the shortcuts making a confirmation."""
    reset = QMessageBox.warning(
        self,
        _("Shortcuts reset"),
        _("Do you want to reset to default values?"),
        QMessageBox.Yes | QMessageBox.No,
    )
    if reset == QMessageBox.No:
        return
    CONF.reset_shortcuts()
    self.main.apply_shortcuts()
    self.table.load_shortcuts()
    self.load_from_conf()
    self.set_modified(False)


# Traceback (AttributeError)
File "C:\Anaconda3\lib\site-packages\spyder\preferences\shortcuts.py", line 850, in reset_to_default
CONF.reset_shortcuts()
File "C:\Anaconda3\lib\site-packages\spyder\config\manager.py", line 322, in reset_shortcuts
plugin_config.reset_to_defaults(section='shortcuts')
AttributeError: 'str' object has no attribute 'reset_to_defaults'

# Fixed code
def reset_to_default(self, force=False):
    """Reset to default values of the shortcuts making a confirmation."""
    if not force:
        reset = QMessageBox.warning(
            self,
            _("Shortcuts reset"),
            _("Do you want to reset to default values?"),
            QMessageBox.Yes | QMessageBox.No,
        )
        if reset == QMessageBox.No:
            return

    CONF.reset_shortcuts()
    self.main.apply_shortcuts()
    self.table.load_shortcuts()
    self.load_from_conf()
    self.set_modified(False)
# Buggy code
def accept(self):
    """Reimplement Qt method"""
    for index in range(self.stack.count()):
        self.stack.widget(index).accept_changes()
    QDialog.accept(self)


# Traceback (TypeError)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\widgets\variableexplorer\arrayeditor.py", line 331, in setData
if val < self.vmin:
TypeError: '<' not supported between instances of 'float' and 'complex'
WARNING:spyder.widgets.github.backend:failed to send bug report on github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}

# Fixed code
def accept(self):
    """Reimplement Qt method."""
    try:
        for index in range(self.stack.count()):
            self.stack.widget(index).accept_changes()
        QDialog.accept(self)
    except RuntimeError:
        # Sometimes under CI testing the object the following error appears
        # RuntimeError: wrapped C/C++ object has been deleted
        pass
# Buggy code
def set_enabled(self, state):
    """Toggle edge line visibility."""
    self._enabled = state
    self.setVisible(state)


# Traceback (KeyError)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response

Traceback (most recent call last):
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response
self._maybe_send_locked(req_id)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 161, in _maybe_send_locked
send()
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 143, in send
self.gather_and_send(request_responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 212, in gather_and_send
response_instance.handle_response(req_type, responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 928, in handle_response
handler(params)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 1325, in handle_folding_range
folding_panel.update_folding(ranges)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/panels/codefolding.py", line 220, in update_folding
folding_status[new_line] = self.folding_status[line]
KeyError: 297

# Fixed code
def set_enabled(self, state):
    """Toggle edge line visibility."""
    self._enabled = state
    self.setVisible(state)

    # We need to request folding when toggling state so the lines
    # are computed when handling the folding response.
    self.editor.request_folding()
# Buggy code
def start_completion_services(self):
    logger.debug("Completions services available for: {0}".format(self.filename))
    self.completions_available = True
    self.document_did_open()
    self.request_folding()


# Traceback (KeyError)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response

Traceback (most recent call last):
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response
self._maybe_send_locked(req_id)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 161, in _maybe_send_locked
send()
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 143, in send
self.gather_and_send(request_responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 212, in gather_and_send
response_instance.handle_response(req_type, responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 928, in handle_response
handler(params)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 1325, in handle_folding_range
folding_panel.update_folding(ranges)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/panels/codefolding.py", line 220, in update_folding
folding_status[new_line] = self.folding_status[line]
KeyError: 297

# Fixed code
def start_completion_services(self):
    logger.debug("Completions services available for: {0}".format(self.filename))
    self.completions_available = True
    self.document_did_open()
# Buggy code
def update_completion_configuration(self, config):
    """Start LSP integration if it wasn't done before."""
    logger.debug("LSP available for: %s" % self.filename)
    self.parse_lsp_config(config)
    self.completions_available = True
    self.document_did_open()
    self.request_folding()


# Traceback (KeyError)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response

Traceback (most recent call last):
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response
self._maybe_send_locked(req_id)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 161, in _maybe_send_locked
send()
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 143, in send
self.gather_and_send(request_responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 212, in gather_and_send
response_instance.handle_response(req_type, responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 928, in handle_response
handler(params)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 1325, in handle_folding_range
folding_panel.update_folding(ranges)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/panels/codefolding.py", line 220, in update_folding
folding_status[new_line] = self.folding_status[line]
KeyError: 297

# Fixed code
def update_completion_configuration(self, config):
    """Start LSP integration if it wasn't done before."""
    logger.debug("LSP available for: %s" % self.filename)
    self.parse_lsp_config(config)
    self.completions_available = True
    self.document_did_open()
# Buggy code
def document_did_change(self, text=None):
    """Send textDocument/didChange request to the server."""
    self.text_version += 1
    text = self.toPlainText()
    self.patch = self.differ.patch_make(self.previous_text, text)
    self.text_diff = (
        self.differ.diff_main(self.previous_text, text),
        self.previous_text,
    )
    self.previous_text = text
    if len(self.patch) > 0:
        line, column = self.get_cursor_line_column()
        self.update_whitespace_count(line, column)
    cursor = self.textCursor()
    params = {
        "file": self.filename,
        "version": self.text_version,
        "text": text,
        "diff": self.patch,
        "offset": cursor.position(),
        "selection_start": cursor.selectionStart(),
        "selection_end": cursor.selectionEnd(),
    }
    return params


# Traceback (KeyError)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response

Traceback (most recent call last):
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response
self._maybe_send_locked(req_id)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 161, in _maybe_send_locked
send()
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 143, in send
self.gather_and_send(request_responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 212, in gather_and_send
response_instance.handle_response(req_type, responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 928, in handle_response
handler(params)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 1325, in handle_folding_range
folding_panel.update_folding(ranges)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/panels/codefolding.py", line 220, in update_folding
folding_status[new_line] = self.folding_status[line]
KeyError: 297

# Fixed code
def document_did_change(self, text=None):
    """Send textDocument/didChange request to the server."""
    self.text_version += 1
    text = self.toPlainText()
    self.patch = self.differ.patch_make(self.previous_text, text)
    self.previous_text = text
    cursor = self.textCursor()
    params = {
        "file": self.filename,
        "version": self.text_version,
        "text": text,
        "diff": self.patch,
        "offset": cursor.position(),
        "selection_start": cursor.selectionStart(),
        "selection_end": cursor.selectionEnd(),
    }
    return params
# Buggy code
def process_diagnostics(self, params):
    """Handle linting response."""
    try:
        self.process_code_analysis(params["params"])
    except RuntimeError:
        # This is triggered when a codeeditor instance has been
        # removed before the response can be processed.
        return
    except Exception:
        self.log_lsp_handle_errors("Error when processing linting")


# Traceback (KeyError)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response

Traceback (most recent call last):
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response
self._maybe_send_locked(req_id)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 161, in _maybe_send_locked
send()
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 143, in send
self.gather_and_send(request_responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 212, in gather_and_send
response_instance.handle_response(req_type, responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 928, in handle_response
handler(params)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 1325, in handle_folding_range
folding_panel.update_folding(ranges)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/panels/codefolding.py", line 220, in update_folding
folding_status[new_line] = self.folding_status[line]
KeyError: 297

# Fixed code
def process_diagnostics(self, params):
    """Handle linting response."""
    try:
        # The LSP spec doesn't require that folding be treated
        # in the same way as linting, i.e. to be recomputed on
        # didChange, didOpen and didSave. However, we think
        # that's necessary to maintain accurate folding all the
        # time. Therefore, we decided to add this request here.
        self.request_folding()

        self.process_code_analysis(params["params"])
    except RuntimeError:
        # This is triggered when a codeeditor instance was removed
        # before the response can be processed.
        return
    except Exception:
        self.log_lsp_handle_errors("Error when processing linting")
# Buggy code
def handle_go_to_definition(self, position):
    """Handle go to definition response."""
    try:
        position = position["params"]
        if position is not None:
            def_range = position["range"]
            start = def_range["start"]
            if self.filename == position["file"]:
                self.go_to_line(start["line"] + 1, start["character"], None, word=None)
            else:
                self.go_to_definition.emit(
                    position["file"], start["line"] + 1, start["character"]
                )
    except RuntimeError:
        # This is triggered when a codeeditor instance has been
        # removed before the response can be processed.
        return
    except Exception:
        self.log_lsp_handle_errors("Error when processing go to definition")


# Traceback (KeyError)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response

Traceback (most recent call last):
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response
self._maybe_send_locked(req_id)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 161, in _maybe_send_locked
send()
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 143, in send
self.gather_and_send(request_responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 212, in gather_and_send
response_instance.handle_response(req_type, responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 928, in handle_response
handler(params)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 1325, in handle_folding_range
folding_panel.update_folding(ranges)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/panels/codefolding.py", line 220, in update_folding
folding_status[new_line] = self.folding_status[line]
KeyError: 297

# Fixed code
def handle_go_to_definition(self, position):
    """Handle go to definition response."""
    try:
        position = position["params"]
        if position is not None:
            def_range = position["range"]
            start = def_range["start"]
            if self.filename == position["file"]:
                self.go_to_line(start["line"] + 1, start["character"], None, word=None)
            else:
                self.go_to_definition.emit(
                    position["file"], start["line"] + 1, start["character"]
                )
    except RuntimeError:
        # This is triggered when a codeeditor instance was removed
        # before the response can be processed.
        return
    except Exception:
        self.log_lsp_handle_errors("Error when processing go to definition")
# Buggy code
def request_folding(self):
    if not self.folding_supported or not self.code_folding:
        return
    params = {"file": self.filename}
    return params


# Traceback (KeyError)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response

Traceback (most recent call last):
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response
self._maybe_send_locked(req_id)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 161, in _maybe_send_locked
send()
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 143, in send
self.gather_and_send(request_responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 212, in gather_and_send
response_instance.handle_response(req_type, responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 928, in handle_response
handler(params)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 1325, in handle_folding_range
folding_panel.update_folding(ranges)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/panels/codefolding.py", line 220, in update_folding
folding_status[new_line] = self.folding_status[line]
KeyError: 297

# Fixed code
def request_folding(self):
    """Request folding."""
    if not self.folding_supported or not self.code_folding:
        return
    params = {"file": self.filename}
    return params
# Buggy code
def handle_folding_range(self, response):
    ranges = response["params"]
    folding_panel = self.panels.get(FoldingPanel)
    folding_panel.update_folding(ranges)


# Traceback (KeyError)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response

Traceback (most recent call last):
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response
self._maybe_send_locked(req_id)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 161, in _maybe_send_locked
send()
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 143, in send
self.gather_and_send(request_responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 212, in gather_and_send
response_instance.handle_response(req_type, responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 928, in handle_response
handler(params)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 1325, in handle_folding_range
folding_panel.update_folding(ranges)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/panels/codefolding.py", line 220, in update_folding
folding_status[new_line] = self.folding_status[line]
KeyError: 297

# Fixed code
def handle_folding_range(self, response):
    """Handle folding response."""
    try:
        ranges = response["params"]
        folding_panel = self.panels.get(FoldingPanel)

        # Update folding
        text = self.toPlainText()
        self.text_diff = (
            self.differ.diff_main(self.previous_text, text),
            self.previous_text,
        )
        folding_panel.update_folding(ranges)

        # Update indent guides, which depend on folding
        if self.indent_guides._enabled and len(self.patch) > 0:
            line, column = self.get_cursor_line_column()
            self.update_whitespace_count(line, column)
    except RuntimeError:
        # This is triggered when a codeeditor instance was removed
        # before the response can be processed.
        return
    except Exception:
        self.log_lsp_handle_errors("Error when processing folding")
# Buggy code
def undo(self):
    """Reimplement undo to decrease text version number."""
    if self.document().isUndoAvailable():
        self.text_version -= 1
        self.skip_rstrip = True
        TextEditBaseWidget.undo(self)
        self.document_did_change("")
        self.request_folding()
        self.sig_undo.emit()
        self.sig_text_was_inserted.emit()
        self.skip_rstrip = False


# Traceback (KeyError)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response

Traceback (most recent call last):
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response
self._maybe_send_locked(req_id)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 161, in _maybe_send_locked
send()
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 143, in send
self.gather_and_send(request_responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 212, in gather_and_send
response_instance.handle_response(req_type, responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 928, in handle_response
handler(params)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 1325, in handle_folding_range
folding_panel.update_folding(ranges)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/panels/codefolding.py", line 220, in update_folding
folding_status[new_line] = self.folding_status[line]
KeyError: 297

# Fixed code
def undo(self):
    """Reimplement undo to decrease text version number."""
    if self.document().isUndoAvailable():
        self.text_version -= 1
        self.skip_rstrip = True
        TextEditBaseWidget.undo(self)
        self.document_did_change("")
        self.sig_undo.emit()
        self.sig_text_was_inserted.emit()
        self.skip_rstrip = False
# Buggy code
def redo(self):
    """Reimplement redo to increase text version number."""
    if self.document().isRedoAvailable():
        self.text_version += 1
        self.skip_rstrip = True
        TextEditBaseWidget.redo(self)
        self.document_did_change("text")
        self.request_folding()
        self.sig_redo.emit()
        self.sig_text_was_inserted.emit()
        self.skip_rstrip = False


# Traceback (KeyError)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response

Traceback (most recent call last):
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response
self._maybe_send_locked(req_id)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 161, in _maybe_send_locked
send()
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 143, in send
self.gather_and_send(request_responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 212, in gather_and_send
response_instance.handle_response(req_type, responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 928, in handle_response
handler(params)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 1325, in handle_folding_range
folding_panel.update_folding(ranges)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/panels/codefolding.py", line 220, in update_folding
folding_status[new_line] = self.folding_status[line]
KeyError: 297

# Fixed code
def redo(self):
    """Reimplement redo to increase text version number."""
    if self.document().isRedoAvailable():
        self.text_version += 1
        self.skip_rstrip = True
        TextEditBaseWidget.redo(self)
        self.document_did_change("text")
        self.sig_redo.emit()
        self.sig_text_was_inserted.emit()
        self.skip_rstrip = False
# Buggy code
def __init__(self, parent, font=None, color_scheme="Spyder"):
    QSyntaxHighlighter.__init__(self, parent)

    self.font = font
    if is_text_string(color_scheme):
        self.color_scheme = get_color_scheme(color_scheme)
    else:
        self.color_scheme = color_scheme

    self.background_color = None
    self.currentline_color = None
    self.currentcell_color = None
    self.occurrence_color = None
    self.ctrlclick_color = None
    self.sideareas_color = None
    self.matched_p_color = None
    self.unmatched_p_color = None

    self.formats = None
    self.setup_formats(font)

    self.cell_separators = None
    self.request_folding = True
    self.editor = None
    self.patterns = DEFAULT_COMPILED_PATTERNS


# Traceback (KeyError)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response

Traceback (most recent call last):
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response
self._maybe_send_locked(req_id)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 161, in _maybe_send_locked
send()
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 143, in send
self.gather_and_send(request_responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 212, in gather_and_send
response_instance.handle_response(req_type, responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 928, in handle_response
handler(params)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 1325, in handle_folding_range
folding_panel.update_folding(ranges)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/panels/codefolding.py", line 220, in update_folding
folding_status[new_line] = self.folding_status[line]
KeyError: 297

# Fixed code
def __init__(self, parent, font=None, color_scheme="Spyder"):
    QSyntaxHighlighter.__init__(self, parent)

    self.font = font
    if is_text_string(color_scheme):
        self.color_scheme = get_color_scheme(color_scheme)
    else:
        self.color_scheme = color_scheme

    self.background_color = None
    self.currentline_color = None
    self.currentcell_color = None
    self.occurrence_color = None
    self.ctrlclick_color = None
    self.sideareas_color = None
    self.matched_p_color = None
    self.unmatched_p_color = None

    self.formats = None
    self.setup_formats(font)

    self.cell_separators = None
    self.editor = None
    self.patterns = DEFAULT_COMPILED_PATTERNS
# Buggy code
def highlightBlock(self, text):
    """
    Highlights a block of text. Please do not override, this method.
    Instead you should implement
    :func:`spyder.utils.syntaxhighplighters.SyntaxHighlighter.highlight_block`.

    :param text: text to highlight.
    """
    self.highlight_block(text)
    if self.request_folding:
        if self.editor is not None:
            if self.editor.folding_supported and self.editor.code_folding:
                diff, _ = self.editor.text_diff
                if len(diff) > 0:
                    self.editor.request_folding()


# Traceback (KeyError)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response

Traceback (most recent call last):
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response
self._maybe_send_locked(req_id)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 161, in _maybe_send_locked
send()
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 143, in send
self.gather_and_send(request_responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 212, in gather_and_send
response_instance.handle_response(req_type, responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 928, in handle_response
handler(params)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 1325, in handle_folding_range
folding_panel.update_folding(ranges)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/panels/codefolding.py", line 220, in update_folding
folding_status[new_line] = self.folding_status[line]
KeyError: 297

# Fixed code
def highlightBlock(self, text):
    """
    Highlights a block of text. Please do not override, this method.
    Instead you should implement
    :func:`spyder.utils.syntaxhighplighters.SyntaxHighlighter.highlight_block`.

    :param text: text to highlight.
    """
    self.highlight_block(text)
# Buggy code
def rehighlight(self):
    QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
    self.request_folding = False
    QSyntaxHighlighter.rehighlight(self)
    self.request_folding = True
    QApplication.restoreOverrideCursor()


# Traceback (KeyError)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response

Traceback (most recent call last):
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 120, in receive_response
self._maybe_send_locked(req_id)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 161, in _maybe_send_locked
send()
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 143, in send
self.gather_and_send(request_responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/completion/plugin.py", line 212, in gather_and_send
response_instance.handle_response(req_type, responses)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 928, in handle_response
handler(params)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/widgets/codeeditor.py", line 1325, in handle_folding_range
folding_panel.update_folding(ranges)
File "/home/carlos/Projects/spyder/github-repo/spyder/plugins/editor/panels/codefolding.py", line 220, in update_folding
folding_status[new_line] = self.folding_status[line]
KeyError: 297

# Fixed code
def rehighlight(self):
    QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
    QSyntaxHighlighter.rehighlight(self)
    QApplication.restoreOverrideCursor()
# Buggy code
def open_switcher_dlg(self, initial_text=""):
    """Open file list management dialog box"""
    if not self.tabs.count():
        return
    if self.switcher_dlg is not None and self.switcher_dlg.isVisible():
        self.switcher_dlg.hide()
        self.switcher_dlg.clear()
        return
    if self.switcher_dlg is None:
        from spyder.widgets.switcher import Switcher

        self.switcher_dlg = Switcher(self)
        self.switcher_manager = EditorSwitcherManager(
            self.switcher_dlg,
            lambda: self.get_current_editor(),
            lambda: self,
            section=self.get_plugin_title(),
        )

    self.switcher_dlg.set_search_text(initial_text)
    self.switcher_dlg.setup()
    self.switcher_dlg.show()
    # Note: the +1 pixel on the top makes it look better
    delta_top = (
        self.tabs.tabBar().geometry().height()
        + self.fname_label.geometry().height()
        + 1
    )
    self.switcher_dlg.set_position(delta_top)


# Traceback (TypeError)
Traceback (most recent call last):
File "C:\Users\User\spyder\spyder\plugins\editor\widgets\editor.py", line 897, in open_switcher_dlg
section=self.get_plugin_title())
TypeError: __init__() missing 1 required positional argument: 'get_editorstack'

# Fixed code
def open_switcher_dlg(self, initial_text=""):
    """Open file list management dialog box"""
    if not self.tabs.count():
        return
    if self.switcher_dlg is not None and self.switcher_dlg.isVisible():
        self.switcher_dlg.hide()
        self.switcher_dlg.clear()
        return
    if self.switcher_dlg is None:
        from spyder.widgets.switcher import Switcher

        self.switcher_dlg = Switcher(self)
        self.switcher_manager = EditorSwitcherManager(
            self.get_plugin(),
            self.switcher_dlg,
            lambda: self.get_current_editor(),
            lambda: self,
            section=self.get_plugin_title(),
        )

    self.switcher_dlg.set_search_text(initial_text)
    self.switcher_dlg.setup()
    self.switcher_dlg.show()
    # Note: the +1 pixel on the top makes it look better
    delta_top = (
        self.tabs.tabBar().geometry().height()
        + self.fname_label.geometry().height()
        + 1
    )
    self.switcher_dlg.set_position(delta_top)
# Buggy code
def get_plugin_title(self):
    """Get the plugin title of the parent widget."""
    # Needed for the editor stack to use its own switcher instance.
    # See spyder-ide/spyder#9469.
    return self.parent().plugin.get_plugin_title()


# Traceback (TypeError)
Traceback (most recent call last):
File "C:\Users\User\spyder\spyder\plugins\editor\widgets\editor.py", line 897, in open_switcher_dlg
section=self.get_plugin_title())
TypeError: __init__() missing 1 required positional argument: 'get_editorstack'

# Fixed code
def get_plugin_title(self):
    """Get the plugin title of the parent widget."""
    # Needed for the editor stack to use its own switcher instance.
    # See spyder-ide/spyder#9469.
    return self.get_plugin().get_plugin_title()
# Buggy code
def stop(self):
    self.observer.stop()
    self.observer.join()
    del self.observer


# Traceback (OSError)
#spyder3
Attribute Qt::AA_ShareOpenGLContexts must be set before QCoreApplication is created.
Attribute Qt::AA_UseSoftwareOpenGL must be set before QCoreApplication is created.
Traceback (most recent call last):
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/spyder/app/mainwindow.py", line 3646, in main
mainwindow = run_spyder(app, options, args)
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/spyder/app/mainwindow.py", line 3498, in run_spyder
main.post_visible_setup()
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/spyder/app/mainwindow.py", line 1415, in post_visible_setup
self.projects.reopen_last_project()
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/spyder/plugins/projects/plugin.py", line 404, in reopen_last_project
save_previous_files=False)
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/spyder/plugins/projects/plugin.py", line 322, in open_project
self.watcher.start(path)
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/spyder/plugins/projects/utils/watcher.py", line 93, in start
self.observer.start()
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/watchdog/observers/api.py", line 255, in start
emitter.start()
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/watchdog/utils/__init__.py", line 110, in start
self.on_thread_start()
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/watchdog/observers/inotify.py", line 121, in on_thread_start
self._inotify = InotifyBuffer(path, self.watch.is_recursive)
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/watchdog/observers/inotify_buffer.py", line 35, in __init__
self._inotify = Inotify(path, recursive)
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/watchdog/observers/inotify_c.py", line 199, in __init__
self._add_dir_watch(path, recursive, event_mask)
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/watchdog/observers/inotify_c.py", line 387, in _add_dir_watch
self._add_watch(full_path, mask)
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/watchdog/observers/inotify_c.py", line 401, in _add_watch
Inotify._raise_error()
File "/home/detlef/tf-2-nightly-gpu/lib/python3.6/site-packages/watchdog/observers/inotify_c.py", line 413, in _raise_error
raise OSError("inotify watch limit reached")
OSError: inotify watch limit reached

# Fixed code
def stop(self):
    if self.observer is not None:
        self.observer.stop()
        self.observer.join()
        del self.observer
# Buggy code
def gather_default(self, req_type, responses):
    response = ""
    for source in self.SOURCE_PRIORITY[req_type]:
        if source in responses:
            response = responses[source].get("params", "")
            if response:
                break
    return {"params": response}


# Traceback (TypeError)
File "/home/kai/Projects/spyder/4/lib/python3.7/site-packages/spyder/plugins/editor/widgets/codeeditor.py", line 1221, in handle_go_to_definition
def_range = position['range']
TypeError: string indices must be integers

# Fixed code
def gather_default(self, req_type, responses):
    response = None
    for source in self.SOURCE_PRIORITY[req_type]:
        if source in responses:
            response = responses[source].get("params", None)
            if response:
                break
    return {"params": response}
# Buggy code
def handle_hover_response(self, contents):
    """Handle hover response."""
    try:
        content = contents["params"]
        self.sig_display_object_info.emit(content, self._request_hover_clicked)
        if self._show_hint and self._last_point and content:
            # This is located in spyder/widgets/mixins.py
            word = (self._last_hover_word,)
            content = content.replace("\xa0", " ")
            self.show_hint(content, inspect_word=word, at_point=self._last_point)
            self._last_point = None
    except RuntimeError:
        # This is triggered when a codeeditor instance has been
        # removed before the response can be processed.
        return
    except Exception:
        self.log_lsp_handle_errors("Error when processing hover")


# Traceback (TypeError)
File "/home/kai/Projects/spyder/4/lib/python3.7/site-packages/spyder/plugins/editor/widgets/codeeditor.py", line 1221, in handle_go_to_definition
def_range = position['range']
TypeError: string indices must be integers

# Fixed code
def handle_hover_response(self, contents):
    """Handle hover response."""
    try:
        content = contents["params"]
        self.sig_display_object_info.emit(content, self._request_hover_clicked)
        if content is not None and self._show_hint and self._last_point:
            # This is located in spyder/widgets/mixins.py
            word = (self._last_hover_word,)
            content = content.replace("\xa0", " ")
            self.show_hint(content, inspect_word=word, at_point=self._last_point)
            self._last_point = None
    except RuntimeError:
        # This is triggered when a codeeditor instance has been
        # removed before the response can be processed.
        return
    except Exception:
        self.log_lsp_handle_errors("Error when processing hover")
# Buggy code
def __getattribute__(self, attr):
    value = object.__getattribute__(self, attr)
    if attr.endswith("ENDPOINT"):
        verb, path = value
        url = "{0}{1}".format(self.KITE_URL, path)
        return verb.lower(), url
    return value


# Traceback (UnicodeEncodeError)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 59: ordinal not in range(128)
Traceback (most recent call last):
File "/Users/gpena-castellanos/Google Drive/develop/quansight/spyder/spyder/plugins/completion/kite/client.py", line 131, in perform_request
response = handler(params)
File "/Users/gpena-castellanos/Google Drive/develop/quansight/spyder/spyder/plugins/completion/kite/decorators.py", line 20, in wrapper
params = req(self, *args, **kwargs)
File "/Users/gpena-castellanos/Google Drive/develop/quansight/spyder/spyder/plugins/completion/kite/providers/document.py", line 79, in document_did_open
self.get_status(params['file'])
File "/Users/gpena-castellanos/Google Drive/develop/quansight/spyder/spyder/plugins/completion/kite/client.py", line 89, in get_status
kite_status = self._get_status(filename)
File "/Users/gpena-castellanos/Google Drive/develop/quansight/spyder/spyder/plugins/completion/kite/client.py", line 81, in _get_status
url = url.format(filename=filename)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 59: ordinal not in range(128)

# Fixed code
def __getattribute__(self, attr):
    value = object.__getattribute__(self, attr)
    if attr.endswith("ENDPOINT"):
        verb, path = value
        url = "{0}{1}".format(self.KITE_URL, path)
        return verb.lower(), url
    return value