gurudesh/pytracebugs huggingface dataset:
# Buggy code
def show_completion_widget(self, textlist):
    """Show completion widget"""
    self.completion_widget.show_list(textlist)


# Traceback (AttributeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\client.py", line 230, in on_msg_received
handler(resp['result'], req_id)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\providers\document.py", line 117, in process_document_completion
LSPRequestTypes.DOCUMENT_COMPLETION, {'params': response})
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 690, in handle_response
handler(params)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 790, in process_completion
self.completion_widget.show_list(completion_list, position)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 159, in show_list
self.update_current()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 222, in update_current
completion_label = completion.lower()
AttributeError: 'dict' object has no attribute 'lower'

# Fixed code
def show_completion_widget(self, textlist):
    """Show completion widget"""
    self.completion_widget.show_list(textlist, position=None)
# Buggy code
def __init__(self, parent, ancestor):
    QListWidget.__init__(self, ancestor)
    self.setWindowFlags(Qt.SubWindow | Qt.FramelessWindowHint)
    self.textedit = parent
    self.completion_list = None
    self.case_sensitive = False
    self.enter_select = None
    self.hide()
    self.itemActivated.connect(self.item_selected)
    self.currentRowChanged.connect(self.row_changed)
    self.is_internal_console = False


# Traceback (AttributeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\client.py", line 230, in on_msg_received
handler(resp['result'], req_id)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\providers\document.py", line 117, in process_document_completion
LSPRequestTypes.DOCUMENT_COMPLETION, {'params': response})
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 690, in handle_response
handler(params)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 790, in process_completion
self.completion_widget.show_list(completion_list, position)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 159, in show_list
self.update_current()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 222, in update_current
completion_label = completion.lower()
AttributeError: 'dict' object has no attribute 'lower'

# Fixed code
def __init__(self, parent, ancestor):
    QListWidget.__init__(self, ancestor)
    self.setWindowFlags(Qt.SubWindow | Qt.FramelessWindowHint)
    self.textedit = parent
    self.completion_list = None
    self.hide()
    self.itemActivated.connect(self.item_selected)
    self.currentRowChanged.connect(self.row_changed)
    self.is_internal_console = False
# Buggy code
def update_current(self):
    completion_text = to_text_string(self.textedit.get_current_word(completion=True))
    if completion_text:
        for row, completion in enumerate(self.completion_list):
            if not self.is_internal_console:
                completion_label = completion["filterText"]
            else:
                completion_label = completion[0]

            if not self.case_sensitive:
                print(completion_text)  # spyder: test-skip
                completion_label = completion.lower()
                completion_text = completion_text.lower()
            if completion_label.startswith(completion_text):
                self.setCurrentRow(row)
                self.scrollTo(self.currentIndex(), QAbstractItemView.PositionAtTop)
                break
    else:
        self.hide()


# Traceback (AttributeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\client.py", line 230, in on_msg_received
handler(resp['result'], req_id)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\providers\document.py", line 117, in process_document_completion
LSPRequestTypes.DOCUMENT_COMPLETION, {'params': response})
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 690, in handle_response
handler(params)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 790, in process_completion
self.completion_widget.show_list(completion_list, position)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 159, in show_list
self.update_current()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 222, in update_current
completion_label = completion.lower()
AttributeError: 'dict' object has no attribute 'lower'

# Fixed code
def update_current(self):
    completion_text = to_text_string(self.textedit.get_current_word(completion=True))
    if completion_text:
        for row, completion in enumerate(self.completion_list):
            if not self.is_internal_console:
                completion_label = completion["filterText"]
            else:
                completion_label = completion[0]

            if completion_label.startswith(completion_text):
                self.setCurrentRow(row)
                self.scrollTo(self.currentIndex(), QAbstractItemView.PositionAtTop)
                break
    else:
        self.hide()
# Buggy code
def handle_hover_response(self, contents):
    text = contents["params"]
    self.sig_display_signature.emit(text)
    self.show_calltip(_("Hint"), text, at_point=self.mouse_point)


# Traceback (AttributeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\client.py", line 230, in on_msg_received
handler(resp['result'], req_id)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\providers\document.py", line 117, in process_document_completion
LSPRequestTypes.DOCUMENT_COMPLETION, {'params': response})
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 690, in handle_response
handler(params)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 790, in process_completion
self.completion_widget.show_list(completion_list, position)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 159, in show_list
self.update_current()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 222, in update_current
completion_label = completion.lower()
AttributeError: 'dict' object has no attribute 'lower'

# Fixed code
def handle_hover_response(self, contents):
    text = contents["params"]
    self.sig_display_signature.emit(text)
    self.show_calltip(_("Hint"), text)
# Buggy code
def go_to_definition_from_cursor(self, cursor=None):
    """Go to definition from cursor instance (QTextCursor)"""
    if not self.go_to_definition_enabled or not self.lsp_go_to_definition_enabled:
        return
    if cursor is None:
        cursor = self.textCursor()
    if self.in_comment_or_string():
        return
    # position = cursor.position()
    text = to_text_string(cursor.selectedText())
    if len(text) == 0:
        cursor.select(QTextCursor.WordUnderCursor)
        text = to_text_string(cursor.selectedText())
    if text is not None:
        # self.go_to_definition.emit(position)
        line, column = self.get_cursor_line_column()
        params = {"file": self.filename, "line": line, "column": column}
        return params


# Traceback (AttributeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\client.py", line 230, in on_msg_received
handler(resp['result'], req_id)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\providers\document.py", line 117, in process_document_completion
LSPRequestTypes.DOCUMENT_COMPLETION, {'params': response})
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 690, in handle_response
handler(params)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 790, in process_completion
self.completion_widget.show_list(completion_list, position)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 159, in show_list
self.update_current()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 222, in update_current
completion_label = completion.lower()
AttributeError: 'dict' object has no attribute 'lower'

# Fixed code
def go_to_definition_from_cursor(self, cursor=None):
    """Go to definition from cursor instance (QTextCursor)"""
    if not self.go_to_definition_enabled or self.in_comment_or_string():
        return
    if cursor is None:
        cursor = self.textCursor()
    text = to_text_string(cursor.selectedText())
    if len(text) == 0:
        cursor.select(QTextCursor.WordUnderCursor)
        text = to_text_string(cursor.selectedText())
    if text is not None:
        line, column = self.get_cursor_line_column()
        params = {"file": self.filename, "line": line, "column": column}
        return params
# Buggy code
def has_markers(self):
    """Return True if this editorstack has a marker margin for TODOs or
    code analysis"""
    return self.todolist_enabled or self.pyflakes_enabled or self.pep8_enabled


# Traceback (AttributeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\client.py", line 230, in on_msg_received
handler(resp['result'], req_id)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\providers\document.py", line 117, in process_document_completion
LSPRequestTypes.DOCUMENT_COMPLETION, {'params': response})
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 690, in handle_response
handler(params)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 790, in process_completion
self.completion_widget.show_list(completion_list, position)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 159, in show_list
self.update_current()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 222, in update_current
completion_label = completion.lower()
AttributeError: 'dict' object has no attribute 'lower'

# Fixed code
def has_markers(self):
    """Return True if this editorstack has a marker margin for TODOs or
    code analysis"""
    return self.todolist_enabled
# Buggy code
def start_stop_analysis_timer(self):
    self.is_analysis_done = False
    if self.realtime_analysis_enabled:
        self.analysis_timer.stop()
        self.analysis_timer.start()


# Traceback (AttributeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\client.py", line 230, in on_msg_received
handler(resp['result'], req_id)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\providers\document.py", line 117, in process_document_completion
LSPRequestTypes.DOCUMENT_COMPLETION, {'params': response})
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 690, in handle_response
handler(params)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 790, in process_completion
self.completion_widget.show_list(completion_list, position)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 159, in show_list
self.update_current()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 222, in update_current
completion_label = completion.lower()
AttributeError: 'dict' object has no attribute 'lower'

# Fixed code
def start_stop_analysis_timer(self):
    self.is_analysis_done = False
# Buggy code
def __init__(self):
    RemoteEnvDialog.__init__(self, dict(os.environ))


# Traceback (AttributeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\client.py", line 230, in on_msg_received
handler(resp['result'], req_id)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\lsp\providers\document.py", line 117, in process_document_completion
LSPRequestTypes.DOCUMENT_COMPLETION, {'params': response})
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 690, in handle_response
handler(params)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\codeeditor.py", line 790, in process_completion
self.completion_widget.show_list(completion_list, position)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 159, in show_list
self.update_current()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 222, in update_current
completion_label = completion.lower()
AttributeError: 'dict' object has no attribute 'lower'

# Fixed code
def __init__(self, parent=None):
    RemoteEnvDialog.__init__(self, dict(os.environ), parent=parent)
# Buggy code
def file_renamed(self, editor, new_filename):
    """File was renamed, updating outline explorer tree"""
    editor_id = editor.get_id()
    if editor_id in list(self.editor_ids.values()):
        root_item = self.editor_items[editor_id]
        root_item.set_path(new_filename, fullpath=self.show_fullpath)
        self.__sort_toplevel_items()


# Traceback (AttributeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\plugin.py", line 1241, in file_renamed_in_data_in_editorstack
editorstack.rename_in_data(original_filename, filename)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\editor.py", line 1287, in rename_in_data
finfo.editor.oe_proxy, finfo.filename)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\outlineexplorer\widgets.py", line 692, in file_renamed
self.treewidget.file_renamed(editor, new_filename)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\outlineexplorer\widgets.py", line 298, in file_renamed
editor_id = editor.get_id()
AttributeError: 'NoneType' object has no attribute 'get_id'

# Fixed code
def file_renamed(self, editor, new_filename):
    """File was renamed, updating outline explorer tree"""
    if editor is None:
        # This is needed when we can't find an editor to attach
        # the outline explorer to.
        # Fix issue 8813
        return
    editor_id = editor.get_id()
    if editor_id in list(self.editor_ids.values()):
        root_item = self.editor_items[editor_id]
        root_item.set_path(new_filename, fullpath=self.show_fullpath)
        self.__sort_toplevel_items()
# Buggy code
def save_history(self):
    """Save history to a text file in user home directory"""
    try:
        open(self.LOG_PATH, "w").write(
            "\n".join(
                [
                    to_text_string(self.combo.itemText(index))
                    for index in range(self.combo.count())
                ]
            )
        )
    except (UnicodeDecodeError, EnvironmentError):
        pass


# Traceback (UnicodeEncodeError)
File "C:\Users\Aleksey\Anaconda3\lib\site-packages\spyder\widgets\ipythonconsole\control.py", line 61, in keyPressEvent
self._key_paren_left(text)
File "C:\Users\Aleksey\Anaconda3\lib\site-packages\spyder\widgets\ipythonconsole\control.py", line 53, in _key_paren_left
self.show_object_info(last_obj)
File "C:\Users\Aleksey\Anaconda3\lib\site-packages\spyder\widgets\mixins.py", line 693, in show_object_info
self.help.set_object_text(text, ignore_unknown=False)
File "C:\Users\Aleksey\Anaconda3\lib\site-packages\spyder\plugins\help.py", line 777, in set_object_text
self.save_history()
File "C:\Users\Aleksey\Anaconda3\lib\site-packages\spyder\plugins\help.py", line 835, in save_history
for index in range(self.combo.count())] ))
File "C:\Users\Aleksey\Anaconda3\lib\encodings\cp1251.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2029' in position 35: character maps to <undefined>
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'}}
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 save_history(self):
    """Save history to a text file in user home directory"""
    # Don't fail when saving search history to disk
    # See issues 8878 and 6864
    try:
        search_history = [
            to_text_string(self.combo.itemText(index))
            for index in range(self.combo.count())
        ]
        search_history = "\n".join(search_history)
        open(self.LOG_PATH, "w").write(search_history)
    except (UnicodeEncodeError, UnicodeDecodeError, EnvironmentError):
        pass
# Buggy code
def save_lang_conf(value):
    """Save language setting to language config file"""
    with open(LANG_FILE, "w") as f:
        f.write(value)


# Traceback (FileNotFoundError)
File "C:\Users\tracylin.SABRINA\AppData\Local\Continuum\anaconda3\envs\Tracy\lib\site-packages\spyder\app\mainwindow.py", line 2663, in edit_preferences
dlg = ConfigDialog(self)
File "C:\Users\tracylin.SABRINA\AppData\Local\Continuum\anaconda3\envs\Tracy\lib\site-packages\spyder\plugins\configdialog.py", line 190, in __init__
CONF.set('main', 'interface_language', load_lang_conf())
File "C:\Users\tracylin.SABRINA\AppData\Local\Continuum\anaconda3\envs\Tracy\lib\site-packages\spyder\config\base.py", line 361, in load_lang_conf
save_lang_conf(lang)
File "C:\Users\tracylin.SABRINA\AppData\Local\Continuum\anaconda3\envs\Tracy\lib\site-packages\spyder\config\base.py", line 346, in save_lang_conf
with open(LANG_FILE, 'w') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'Temp\\.spyder-py3\\langconfig'

# Fixed code
def save_lang_conf(value):
    """Save language setting to language config file"""
    # Needed to avoid an error when trying to save LANG_FILE
    # but the operation fails for some reason.
    # See issue 8807
    try:
        with open(LANG_FILE, "w") as f:
            f.write(value)
    except EnvironmentError:
        pass
# Buggy code
def current_changed(self, index):
    """Stack index has changed"""
    #        count = self.get_stack_count()
    #        for btn in (self.filelist_btn, self.previous_btn, self.next_btn):
    #            btn.setEnabled(count > 1)

    editor = self.get_current_editor()
    if editor.lsp_ready and not editor.document_opened:
        editor.document_did_open()
    if index != -1:
        editor.setFocus()
        logger.debug("Set focus to: %s" % editor.filename)
    else:
        self.reset_statusbar.emit()
    self.opened_files_list_changed.emit()

    self.stack_history.refresh()
    self.stack_history.remove_and_append(index)

    logger.debug("Current changed: %d - %s" % (index, self.data[index].editor.filename))

    self.update_plugin_title.emit()
    if editor is not None:
        # Needed in order to handle the close of files open in a directory
        # that has been renamed. See issue 5157
        try:
            self.current_file_changed.emit(
                self.data[index].filename, editor.get_position("cursor")
            )
        except IndexError:
            pass


# Traceback (IndexError)
File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/editor/widgets/editor.py", line 1971, in current_changed
(index, self.data[index].editor.filename))
IndexError: list index out of range

# Fixed code
def current_changed(self, index):
    """Stack index has changed"""
    #        count = self.get_stack_count()
    #        for btn in (self.filelist_btn, self.previous_btn, self.next_btn):
    #            btn.setEnabled(count > 1)

    editor = self.get_current_editor()
    if editor.lsp_ready and not editor.document_opened:
        editor.document_did_open()
    if index != -1:
        editor.setFocus()
        logger.debug("Set focus to: %s" % editor.filename)
    else:
        self.reset_statusbar.emit()
    self.opened_files_list_changed.emit()

    self.stack_history.refresh()
    self.stack_history.remove_and_append(index)

    # Needed to avoid an error generated after moving/renaming
    # files outside Spyder while in debug mode.
    # See issue 8749.
    try:
        logger.debug(
            "Current changed: %d - %s" % (index, self.data[index].editor.filename)
        )
    except IndexError:
        pass

    self.update_plugin_title.emit()
    if editor is not None:
        # Needed in order to handle the close of files open in a directory
        # that has been renamed. See issue 5157
        try:
            self.current_file_changed.emit(
                self.data[index].filename, editor.get_position("cursor")
            )
        except IndexError:
            pass
# Buggy code
def load_more_data(self, value, rows=False, columns=False):
    """Load more rows and columns to display."""
    if rows and value == self.verticalScrollBar().maximum():
        self.model().fetch_more(rows=rows)
        self.sig_fetch_more_rows.emit()
    if columns and value == self.horizontalScrollBar().maximum():
        self.model().fetch_more(columns=columns)
        self.sig_fetch_more_columns.emit()


# Traceback (NameError)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\widgets\variableexplorer\dataframeeditor.py", line 513, in <lambda>
lambda val: self.load_more_data(val, rows=True))
NameError: free variable 'self' referenced before assignment in enclosing scope

# Fixed code
def load_more_data(self, value, rows=False, columns=False):
    """Load more rows and columns to display."""
    try:
        if rows and value == self.verticalScrollBar().maximum():
            self.model().fetch_more(rows=rows)
            self.sig_fetch_more_rows.emit()
        if columns and value == self.horizontalScrollBar().maximum():
            self.model().fetch_more(columns=columns)
            self.sig_fetch_more_columns.emit()

    except NameError:
        # Needed to handle a NameError while fetching data when closing
        # See issue 7880
        pass
# Buggy code
def _key_tab(self):
    """Action for TAB key"""
    if self.is_cursor_on_last_line():
        empty_line = not self.get_current_line_to_cursor().strip()
        if empty_line:
            self.stdkey_tab()
        else:
            self.show_code_completion(automatic=False)


# Traceback (TypeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\internalshell.py", line 353, in keyPressEvent
self.postprocess_keyevent(event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 713, in postprocess_keyevent
ShellBaseWidget.postprocess_keyevent(self, event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 362, in postprocess_keyevent
self._key_tab()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 745, in _key_tab
self.show_code_completion(automatic=False)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 893, in show_code_completion
automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1131, in show_completion_list
self.show_completion_widget(completions, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1107, in show_completion_widget
self.completion_widget.show_list(textlist, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 112, in show_list
icon = icons_map.get(completion['kind'], 'no_match')
TypeError: tuple indices must be integers or slices, not str

# Fixed code
def _key_tab(self):
    """Action for TAB key"""
    if self.is_cursor_on_last_line():
        empty_line = not self.get_current_line_to_cursor().strip()
        if empty_line:
            self.stdkey_tab()
        else:
            self.show_code_completion()
# Buggy code
def _key_ctrl_space(self):
    """Action for Ctrl+Space"""
    if not self.is_completion_widget_visible():
        self.show_code_completion(automatic=False)


# Traceback (TypeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\internalshell.py", line 353, in keyPressEvent
self.postprocess_keyevent(event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 713, in postprocess_keyevent
ShellBaseWidget.postprocess_keyevent(self, event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 362, in postprocess_keyevent
self._key_tab()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 745, in _key_tab
self.show_code_completion(automatic=False)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 893, in show_code_completion
automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1131, in show_completion_list
self.show_completion_widget(completions, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1107, in show_completion_widget
self.completion_widget.show_list(textlist, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 112, in show_list
icon = icons_map.get(completion['kind'], 'no_match')
TypeError: tuple indices must be integers or slices, not str

# Fixed code
def _key_ctrl_space(self):
    """Action for Ctrl+Space"""
    if not self.is_completion_widget_visible():
        self.show_code_completion()
# Buggy code
def _key_period(self, text):
    """Action for '.'"""
    self.insert_text(text)
    if self.codecompletion_auto:
        # Enable auto-completion only if last token isn't a float
        last_obj = self.get_last_obj()
        if last_obj and not last_obj.isdigit():
            self.show_code_completion(automatic=True)


# Traceback (TypeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\internalshell.py", line 353, in keyPressEvent
self.postprocess_keyevent(event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 713, in postprocess_keyevent
ShellBaseWidget.postprocess_keyevent(self, event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 362, in postprocess_keyevent
self._key_tab()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 745, in _key_tab
self.show_code_completion(automatic=False)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 893, in show_code_completion
automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1131, in show_completion_list
self.show_completion_widget(completions, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1107, in show_completion_widget
self.completion_widget.show_list(textlist, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 112, in show_list
icon = icons_map.get(completion['kind'], 'no_match')
TypeError: tuple indices must be integers or slices, not str

# Fixed code
def _key_period(self, text):
    """Action for '.'"""
    self.insert_text(text)
    if self.codecompletion_auto:
        # Enable auto-completion only if last token isn't a float
        last_obj = self.get_last_obj()
        if last_obj and not last_obj.isdigit():
            self.show_code_completion()
# Buggy code
def __init__(self, parent, ancestor):
    QListWidget.__init__(self, ancestor)
    self.setWindowFlags(Qt.SubWindow | Qt.FramelessWindowHint)
    self.textedit = parent
    self.completion_list = None
    self.case_sensitive = False
    self.enter_select = None
    self.hide()
    self.itemActivated.connect(self.item_selected)
    self.currentRowChanged.connect(self.row_changed)


# Traceback (TypeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\internalshell.py", line 353, in keyPressEvent
self.postprocess_keyevent(event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 713, in postprocess_keyevent
ShellBaseWidget.postprocess_keyevent(self, event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 362, in postprocess_keyevent
self._key_tab()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 745, in _key_tab
self.show_code_completion(automatic=False)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 893, in show_code_completion
automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1131, in show_completion_list
self.show_completion_widget(completions, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1107, in show_completion_widget
self.completion_widget.show_list(textlist, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 112, in show_list
icon = icons_map.get(completion['kind'], 'no_match')
TypeError: tuple indices must be integers or slices, not str

# Fixed code
def __init__(self, parent, ancestor):
    QListWidget.__init__(self, ancestor)
    self.setWindowFlags(Qt.SubWindow | Qt.FramelessWindowHint)
    self.textedit = parent
    self.completion_list = None
    self.case_sensitive = False
    self.enter_select = None
    self.hide()
    self.itemActivated.connect(self.item_selected)
    self.currentRowChanged.connect(self.row_changed)
    self.is_internal_console = False
# Buggy code
def update_current(self):
    completion_text = to_text_string(self.textedit.completion_text)
    if completion_text:
        for row, completion in enumerate(self.completion_list):
            completion_label = completion["filterText"]
            if not self.case_sensitive:
                print(completion_text)  # spyder: test-skip
                completion_label = completion.lower()
                completion_text = completion_text.lower()
            if completion_label.startswith(completion_text):
                self.setCurrentRow(row)
                self.scrollTo(self.currentIndex(), QAbstractItemView.PositionAtTop)
                break
        # if not match:
        # self.hide()
    else:
        self.hide()


# Traceback (TypeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\internalshell.py", line 353, in keyPressEvent
self.postprocess_keyevent(event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 713, in postprocess_keyevent
ShellBaseWidget.postprocess_keyevent(self, event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 362, in postprocess_keyevent
self._key_tab()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 745, in _key_tab
self.show_code_completion(automatic=False)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 893, in show_code_completion
automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1131, in show_completion_list
self.show_completion_widget(completions, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1107, in show_completion_widget
self.completion_widget.show_list(textlist, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 112, in show_list
icon = icons_map.get(completion['kind'], 'no_match')
TypeError: tuple indices must be integers or slices, not str

# Fixed code
def update_current(self):
    completion_text = to_text_string(self.textedit.completion_text)
    if completion_text:
        for row, completion in enumerate(self.completion_list):
            if not self.is_internal_console:
                completion_label = completion["filterText"]
            else:
                completion_label = completion[0]

            if not self.case_sensitive:
                print(completion_text)  # spyder: test-skip
                completion_label = completion.lower()
                completion_text = completion_text.lower()
            if completion_label.startswith(completion_text):
                self.setCurrentRow(row)
                self.scrollTo(self.currentIndex(), QAbstractItemView.PositionAtTop)
                break
    else:
        self.hide()
# Buggy code
def item_selected(self, item=None):
    if item is None:
        item = self.currentItem()
    # index = self.currentIndex()
    # self.textedit.show_calltip()
    self.textedit.insert_completion(to_text_string(item.text()))
    self.hide()


# Traceback (TypeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\internalshell.py", line 353, in keyPressEvent
self.postprocess_keyevent(event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 713, in postprocess_keyevent
ShellBaseWidget.postprocess_keyevent(self, event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 362, in postprocess_keyevent
self._key_tab()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 745, in _key_tab
self.show_code_completion(automatic=False)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 893, in show_code_completion
automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1131, in show_completion_list
self.show_completion_widget(completions, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1107, in show_completion_widget
self.completion_widget.show_list(textlist, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 112, in show_list
icon = icons_map.get(completion['kind'], 'no_match')
TypeError: tuple indices must be integers or slices, not str

# Fixed code
def item_selected(self, item=None):
    if item is None:
        item = self.currentItem()
    self.textedit.insert_completion(to_text_string(item.text()))
    self.hide()
# Buggy code
def do_completion(self, automatic=False):
    """Trigger completion"""
    # if self.is_completion_widget_visible():
    #     return
    self.document_did_change("")
    line, column = self.get_cursor_line_column()
    params = {"file": self.filename, "line": line, "column": column}
    return params


# Traceback (TypeError)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\internalshell.py", line 353, in keyPressEvent
self.postprocess_keyevent(event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 713, in postprocess_keyevent
ShellBaseWidget.postprocess_keyevent(self, event)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 362, in postprocess_keyevent
self._key_tab()
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 745, in _key_tab
self.show_code_completion(automatic=False)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\console\widgets\shell.py", line 893, in show_code_completion
automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1131, in show_completion_list
self.show_completion_widget(completions, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 1107, in show_completion_widget
self.completion_widget.show_list(textlist, automatic=automatic)
File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\base.py", line 112, in show_list
icon = icons_map.get(completion['kind'], 'no_match')
TypeError: tuple indices must be integers or slices, not str

# Fixed code
def do_completion(self, automatic=False):
    """Trigger completion"""
    self.document_did_change("")
    line, column = self.get_cursor_line_column()
    params = {"file": self.filename, "line": line, "column": column}
    return params
# Buggy code
def editor_accepted(self, editor_id):
    data = self._editors[editor_id]
    if not data["readonly"]:
        index = data["model"].get_index_from_key(data["key"])
        value = data["editor"].get_value()
        conv_func = data.get("conv", lambda v: v)
        self.set_value(index, conv_func(value))
    self._editors.pop(editor_id)
    self.free_memory()


# Traceback (KeyError)
File "/usr/local/lib/python3.6/dist-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 560, in <lambda>
lambda eid=id(editor): self.editor_rejected(eid))
File "/usr/local/lib/python3.6/dist-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 585, in editor_rejected
self._editors.pop(editor_id)
KeyError: 140299497471576
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'}}
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 editor_accepted(self, editor_id):
    data = self._editors[editor_id]
    if not data["readonly"]:
        index = data["model"].get_index_from_key(data["key"])
        value = data["editor"].get_value()
        conv_func = data.get("conv", lambda v: v)
        self.set_value(index, conv_func(value))
    # This is needed to avoid the problem reported on
    # issue 8557
    try:
        self._editors.pop(editor_id)
    except KeyError:
        pass
    self.free_memory()
# Buggy code
def editor_rejected(self, editor_id):
    self._editors.pop(editor_id)
    self.free_memory()


# Traceback (KeyError)
File "/usr/local/lib/python3.6/dist-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 560, in <lambda>
lambda eid=id(editor): self.editor_rejected(eid))
File "/usr/local/lib/python3.6/dist-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 585, in editor_rejected
self._editors.pop(editor_id)
KeyError: 140299497471576
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'}}
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 editor_rejected(self, editor_id):
    # This is needed to avoid the problem reported on
    # issue 8557
    try:
        self._editors.pop(editor_id)
    except KeyError:
        pass
    self.free_memory()
# Buggy code
def item_at_line(root_item, line):
    """
    Find and return the item of the outline explorer under which is located
    the specified 'line' of the editor.
    """
    previous_item = root_item
    for item in get_item_children(root_item):
        if item.line > line:
            return previous_item
        previous_item = item
    else:
        return item


# Traceback (UnboundLocalError)
File "/home/ok97465/python/spyder/spyder/plugins/outlineexplorer/widgets.py", line 257, in go_to_cursor_position
item = item_at_line(root_item, line)
File "/home/ok97465/python/spyder/spyder/plugins/outlineexplorer/widgets.py", line 142, in item_at_line
return item
UnboundLocalError: local variable 'item' referenced before assignment

# Fixed code
def item_at_line(root_item, line):
    """
    Find and return the item of the outline explorer under which is located
    the specified 'line' of the editor.
    """
    previous_item = root_item
    item = root_item
    for item in get_item_children(root_item):
        if item.line > line:
            return previous_item
        previous_item = item
    else:
        return item
# Buggy code
def get_plugin_actions(self):
    """Return a list of actions related to plugin"""
    self.new_project_action = create_action(
        self, _("New Project..."), triggered=self.create_new_project
    )
    self.open_project_action = create_action(
        self, _("Open Project..."), triggered=lambda v: self.open_project()
    )
    self.close_project_action = create_action(
        self, _("Close Project"), triggered=self.close_project
    )
    self.delete_project_action = create_action(
        self, _("Delete Project"), triggered=self._delete_project
    )
    self.clear_recent_projects_action = create_action(
        self, _("Clear this list"), triggered=self.clear_recent_projects
    )
    self.edit_project_preferences_action = create_action(
        self, _("Project Preferences"), triggered=self.edit_project_preferences
    )
    self.recent_project_menu = QMenu(_("Recent Projects"), self)

    if self.main is not None:
        self.main.projects_menu_actions += [
            self.new_project_action,
            MENU_SEPARATOR,
            self.open_project_action,
            self.close_project_action,
            self.delete_project_action,
            MENU_SEPARATOR,
            self.recent_project_menu,
            self.toggle_view_action,
        ]

    self.setup_menu_actions()
    return []


# Traceback (AttributeError)
File "C:\Users\User\spyder\spyder\plugins\projects\plugin.py", line 338, in _delete_project
self.explorer.delete_project()
File "C:\Users\User\spyder\spyder\plugins\projects\widgets\explorer.py", line 239, in delete_project
if self.current_active_project:
AttributeError: 'ProjectExplorerWidget' object has no attribute 'current_active_project'

# Fixed code
def get_plugin_actions(self):
    """Return a list of actions related to plugin"""
    self.new_project_action = create_action(
        self, _("New Project..."), triggered=self.create_new_project
    )
    self.open_project_action = create_action(
        self, _("Open Project..."), triggered=lambda v: self.open_project()
    )
    self.close_project_action = create_action(
        self, _("Close Project"), triggered=self.close_project
    )
    self.delete_project_action = create_action(
        self, _("Delete Project"), triggered=self.delete_project
    )
    self.clear_recent_projects_action = create_action(
        self, _("Clear this list"), triggered=self.clear_recent_projects
    )
    self.edit_project_preferences_action = create_action(
        self, _("Project Preferences"), triggered=self.edit_project_preferences
    )
    self.recent_project_menu = QMenu(_("Recent Projects"), self)

    if self.main is not None:
        self.main.projects_menu_actions += [
            self.new_project_action,
            MENU_SEPARATOR,
            self.open_project_action,
            self.close_project_action,
            self.delete_project_action,
            MENU_SEPARATOR,
            self.recent_project_menu,
            self.toggle_view_action,
        ]

    self.setup_menu_actions()
    return []
# Buggy code
def setup_project(self, directory):
    """Setup project"""
    self.emptywidget.hide()
    self.treewidget.show()

    # Setup the directory shown by the tree
    self.set_project_dir(directory)

    # Signal to delete the project
    self.treewidget.sig_delete_project.connect(self.delete_project)


# Traceback (AttributeError)
File "C:\Users\User\spyder\spyder\plugins\projects\plugin.py", line 338, in _delete_project
self.explorer.delete_project()
File "C:\Users\User\spyder\spyder\plugins\projects\widgets\explorer.py", line 239, in delete_project
if self.current_active_project:
AttributeError: 'ProjectExplorerWidget' object has no attribute 'current_active_project'

# Fixed code
def setup_project(self, directory):
    """Setup project"""
    self.emptywidget.hide()
    self.treewidget.show()

    # Setup the directory shown by the tree
    self.set_project_dir(directory)