gurudesh/pytracebugs huggingface dataset:
# Buggy code
def get_bgcolor(self, index):
    """Background color depending on value."""
    column = index.column()
    if not self.bgcolor_enabled:
        return
    value = self.get_value(index.row(), column)
    if self.max_min_col[column] is None or isna(value):
        color = QColor(BACKGROUND_NONNUMBER_COLOR)
        if is_text_string(value):
            color.setAlphaF(BACKGROUND_STRING_ALPHA)
        else:
            color.setAlphaF(BACKGROUND_MISC_ALPHA)
    else:
        if isinstance(value, COMPLEX_NUMBER_TYPES):
            color_func = abs
        else:
            color_func = float
        vmax, vmin = self.return_max(self.max_min_col, column)
        hue = BACKGROUND_NUMBER_MINHUE + BACKGROUND_NUMBER_HUERANGE * (
            vmax - color_func(value)
        ) / (vmax - vmin)
        hue = float(abs(hue))
        if hue > 1:
            hue = 1
        color = QColor.fromHsvF(
            hue,
            BACKGROUND_NUMBER_SATURATION,
            BACKGROUND_NUMBER_VALUE,
            BACKGROUND_NUMBER_ALPHA,
        )
    return color


# Traceback (ZeroDivisionError)
File "C:\Users\mowang\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\dataframeeditor.py", line 341, in data
return to_qvariant(self.get_bgcolor(index))
File "C:\Users\mowang\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\dataframeeditor.py", line 288, in get_bgcolor
(vmax - color_func(value)) / (vmax - vmin))
ZeroDivisionError: float division by zero

# Fixed code
def get_bgcolor(self, index):
    """Background color depending on value."""
    column = index.column()
    if not self.bgcolor_enabled:
        return
    value = self.get_value(index.row(), column)
    if self.max_min_col[column] is None or isna(value):
        color = QColor(BACKGROUND_NONNUMBER_COLOR)
        if is_text_string(value):
            color.setAlphaF(BACKGROUND_STRING_ALPHA)
        else:
            color.setAlphaF(BACKGROUND_MISC_ALPHA)
    else:
        if isinstance(value, COMPLEX_NUMBER_TYPES):
            color_func = abs
        else:
            color_func = float
        vmax, vmin = self.return_max(self.max_min_col, column)
        if vmax - vmin == 0:
            vmax_vmin_diff = 1.0
        else:
            vmax_vmin_diff = vmax - vmin
        hue = BACKGROUND_NUMBER_MINHUE + BACKGROUND_NUMBER_HUERANGE * (
            vmax - color_func(value)
        ) / (vmax_vmin_diff)
        hue = float(abs(hue))
        if hue > 1:
            hue = 1
        color = QColor.fromHsvF(
            hue,
            BACKGROUND_NUMBER_SATURATION,
            BACKGROUND_NUMBER_VALUE,
            BACKGROUND_NUMBER_ALPHA,
        )
    return color
# Buggy code
def show_log(self):
    if self.output:
        TextEditor(
            self.output,
            title=_("Profiler output"),
            readonly=True,
            size=(700, 500),
            parent=self,
        ).exec_()


# Traceback (TypeError)
Traceback (most recent call last):
File "C:\Users\Slawek\anaconda3\lib\site-packages\spyder\plugins\profiler\widgets\profilergui.py", line 235, in show_log
readonly=True, size=(700, 500), parent=self).exec_()
TypeError: __init__() got an unexpected keyword argument 'size'
Traceback (most recent call last):
File "C:\Users\Slawek\anaconda3\lib\site-packages\spyder\plugins\profiler\widgets\profilergui.py", line 235, in show_log
readonly=True, size=(700, 500), parent=self).exec_()
TypeError: __init__() got an unexpected keyword argument 'size'

# Fixed code
def show_log(self):
    if self.output:
        output_dialog = TextEditor(
            self.output, title=_("Profiler output"), readonly=True, parent=self
        )
        output_dialog.resize(700, 500)
        output_dialog.exec_()
# Buggy code
def show_errorlog(self):
    if self.error_output:
        TextEditor(
            self.error_output,
            title=_("Profiler output"),
            readonly=True,
            size=(700, 500),
            parent=self,
        ).exec_()


# Traceback (TypeError)
Traceback (most recent call last):
File "C:\Users\Slawek\anaconda3\lib\site-packages\spyder\plugins\profiler\widgets\profilergui.py", line 235, in show_log
readonly=True, size=(700, 500), parent=self).exec_()
TypeError: __init__() got an unexpected keyword argument 'size'
Traceback (most recent call last):
File "C:\Users\Slawek\anaconda3\lib\site-packages\spyder\plugins\profiler\widgets\profilergui.py", line 235, in show_log
readonly=True, size=(700, 500), parent=self).exec_()
TypeError: __init__() got an unexpected keyword argument 'size'

# Fixed code
def show_errorlog(self):
    if self.error_output:
        output_dialog = TextEditor(
            self.error_output, title=_("Profiler output"), readonly=True, parent=self
        )
        output_dialog.resize(700, 500)
        output_dialog.exec_()
# Buggy code
def __init__(self, parent, model, dtype, shape):
    QTableView.__init__(self, parent)

    self.setModel(model)
    self.setItemDelegate(ArrayDelegate(dtype, self))
    total_width = 0
    for k in range(shape[1]):
        total_width += self.columnWidth(k)
    self.viewport().resize(min(total_width, 1024), self.height())
    self.shape = shape
    self.menu = self.setup_menu()
    CONF.config_shortcut(
        self.copy, context="variable_explorer", name="copy", parent=self
    )
    self.horizontalScrollBar().valueChanged.connect(
        lambda val: self.load_more_data(val, columns=True)
    )
    self.verticalScrollBar().valueChanged.connect(
        lambda val: self.load_more_data(val, rows=True)
    )


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

# Fixed code
def __init__(self, parent, model, dtype, shape):
    QTableView.__init__(self, parent)

    self.setModel(model)
    self.setItemDelegate(ArrayDelegate(dtype, self))
    total_width = 0
    for k in range(shape[1]):
        total_width += self.columnWidth(k)
    self.viewport().resize(min(total_width, 1024), self.height())
    self.shape = shape
    self.menu = self.setup_menu()
    CONF.config_shortcut(
        self.copy, context="variable_explorer", name="copy", parent=self
    )
    self.horizontalScrollBar().valueChanged.connect(self._load_more_columns)
    self.verticalScrollBar().valueChanged.connect(self._load_more_rows)
# Buggy code
def __init__(self, parent, model, header, hscroll, vscroll):
    """Constructor."""
    QTableView.__init__(self, parent)
    self.setModel(model)
    self.setHorizontalScrollBar(hscroll)
    self.setVerticalScrollBar(vscroll)
    self.setHorizontalScrollMode(1)
    self.setVerticalScrollMode(1)

    self.sort_old = [None]
    self.header_class = header
    self.header_class.sectionClicked.connect(self.sortByColumn)
    self.menu = self.setup_menu()
    CONF.config_shortcut(
        self.copy, context="variable_explorer", name="copy", parent=self
    )
    self.horizontalScrollBar().valueChanged.connect(
        lambda val: self.load_more_data(val, columns=True)
    )
    self.verticalScrollBar().valueChanged.connect(
        lambda val: self.load_more_data(val, rows=True)
    )


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

# Fixed code
def __init__(self, parent, model, header, hscroll, vscroll):
    """Constructor."""
    QTableView.__init__(self, parent)
    self.setModel(model)
    self.setHorizontalScrollBar(hscroll)
    self.setVerticalScrollBar(vscroll)
    self.setHorizontalScrollMode(1)
    self.setVerticalScrollMode(1)

    self.sort_old = [None]
    self.header_class = header
    self.header_class.sectionClicked.connect(self.sortByColumn)
    self.menu = self.setup_menu()
    CONF.config_shortcut(
        self.copy, context="variable_explorer", name="copy", parent=self
    )
    self.horizontalScrollBar().valueChanged.connect(self._load_more_columns)
    self.verticalScrollBar().valueChanged.connect(self._load_more_rows)
# Buggy code
def get_words(text, exclude_offset=None, language=None):
    """
    Extract all words from a source code file to be used in code completion.

    Extract the list of words that contains the file in the editor,
    to carry out the inline completion similar to VSCode.
    """
    regex = LANGUAGE_REGEX.get(language.lower(), all_regex)
    tokens = [
        x
        for x in (
            m.group()
            for m in regex.finditer(text)
            if exclude_offset is None
            or exclude_offset < m.start()
            or m.end() < exclude_offset
        )
        if x != ""
    ]
    return tokens


# Traceback (IndexError)
File "C:\Users\Al\Anaconda3\lib\site-packages\spyder\plugins\completion\fallback\actor.py", line 155, in handle_msg
msg['current_word'])
File "C:\Users\Al\Anaconda3\lib\site-packages\spyder\plugins\completion\fallback\actor.py", line 62, in tokenize
valid = is_prefix_valid(text, offset, language)
File "C:\Users\Al\Anaconda3\lib\site-packages\spyder\plugins\completion\fallback\utils.py", line 122, in is_prefix_valid
current_pos_text = text[offset - 1]
IndexError: string index out of range

# Fixed code
def get_words(text, exclude_offset=None, language=""):
    """
    Extract all words from a source code file to be used in code completion.

    Extract the list of words that contains the file in the editor,
    to carry out the inline completion similar to VSCode.
    """
    regex = LANGUAGE_REGEX.get(language.lower(), all_regex)
    tokens = [
        x
        for x in (
            m.group()
            for m in regex.finditer(text)
            if exclude_offset is None
            or exclude_offset < m.start()
            or m.end() < exclude_offset
        )
        if x != ""
    ]
    return tokens
# Buggy code
def is_prefix_valid(text, offset, language):
    """Check if current offset prefix is valid."""
    regex = LANGUAGE_REGEX.get(language.lower(), all_regex)
    prefix = ""
    current_pos_text = text[offset - 1]
    empty_start = empty_regex.match(current_pos_text) is not None
    max_end = -1
    for match in regex.finditer(text):
        start, end = match.span()
        max_end = max(end, max_end)
        if offset >= start and offset <= end:
            prefix = match.group()
    if offset > max_end:
        if letter_regex.match(current_pos_text):
            prefix = current_pos_text
    valid = prefix != "" or (prefix == "" and empty_start)
    return valid


# Traceback (IndexError)
File "C:\Users\Al\Anaconda3\lib\site-packages\spyder\plugins\completion\fallback\actor.py", line 155, in handle_msg
msg['current_word'])
File "C:\Users\Al\Anaconda3\lib\site-packages\spyder\plugins\completion\fallback\actor.py", line 62, in tokenize
valid = is_prefix_valid(text, offset, language)
File "C:\Users\Al\Anaconda3\lib\site-packages\spyder\plugins\completion\fallback\utils.py", line 122, in is_prefix_valid
current_pos_text = text[offset - 1]
IndexError: string index out of range

# Fixed code
def is_prefix_valid(text, offset, language):
    """Check if current offset prefix is valid."""
    # Account for length differences in text when using characters
    # such as emojis in the editor.
    # Fixes spyder-ide/spyder#11862
    utf16_diff = qstring_length(text) - len(text)
    current_pos_text = text[offset - utf16_diff - 1]

    empty_start = empty_regex.match(current_pos_text) is not None
    max_end = -1
    regex = LANGUAGE_REGEX.get(language.lower(), all_regex)
    prefix = ""

    for match in regex.finditer(text):
        start, end = match.span()
        max_end = max(end, max_end)
        if offset >= start and offset <= end:
            prefix = match.group()
    if offset > max_end:
        if letter_regex.match(current_pos_text):
            prefix = current_pos_text
    valid = prefix != "" or (prefix == "" and empty_start)
    return valid
# Buggy code
def show_log(self):
    if self.output:
        TextEditor(
            self.output,
            title=_("Pylint output"),
            parent=self,
            readonly=True,
            size=(700, 500),
        ).exec_()


# Traceback (TypeError)
File "/home/Saurabh/anaconda3/lib/python3.7/site-packages/spyder/plugins/pylint/widgets/pylintgui.py", line 308, in show_log
readonly=True, size=(700, 500)).exec_()
TypeError: __init__() got an unexpected keyword argument 'size'

# Fixed code
def show_log(self):
    if self.output:
        output_dialog = TextEditor(
            self.output, title=_("Pylint output"), parent=self, readonly=True
        )
        output_dialog.resize(700, 500)
        output_dialog.exec_()
# Buggy code
def handle_new_screen(self, screen):
    """Connect DPI signals for new screen."""
    try:
        self.screen.logicalDotsPerInchChanged.disconnect(self.show_dpi_change_message)
    except TypeError:
        # See spyder-ide/spyder#11903
        pass
    self.screen = screen
    self.screen.logicalDotsPerInchChanged.connect(self.show_dpi_change_message)


# Traceback (RuntimeError)
File "/home/cristiana/anaconda3/envs/fintools/lib/python3.8/site-packages/spyder/app/mainwindow.py", line 1392, in handle_new_screen
self.screen.logicalDotsPerInchChanged.disconnect(
RuntimeError: wrapped C/C++ object of type QScreen has been deleted
Traceback (most recent call last):
File "/home/cristiana/anaconda3/envs/fintools/lib/python3.8/site-packages/spyder/app/mainwindow.py", line 1392, in handle_new_screen
self.screen.logicalDotsPerInchChanged.disconnect(
RuntimeError: wrapped C/C++ object of type QScreen has been deleted
Traceback (most recent call last):
File "/home/cristiana/anaconda3/envs/fintools/lib/python3.8/site-packages/spyder/app/mainwindow.py", line 1392, in handle_new_screen
self.screen.logicalDotsPerInchChanged.disconnect(
RuntimeError: wrapped C/C++ object of type QScreen has been deleted

# Fixed code
def handle_new_screen(self, screen):
    """Connect DPI signals for new screen."""
    try:
        self.screen.logicalDotsPerInchChanged.disconnect(self.show_dpi_change_message)
    except (TypeError, RuntimeError):
        # See spyder-ide/spyder#11903 and spyder-ide/spyder#11997
        pass
    self.screen = screen
    self.screen.logicalDotsPerInchChanged.connect(self.show_dpi_change_message)
# Buggy code
def handle_new_screen(self, screen):
    """Connect DPI signals for new screen."""
    self.screen.logicalDotsPerInchChanged.disconnect(self.show_dpi_change_message)
    self.screen = screen
    self.screen.logicalDotsPerInchChanged.connect(self.show_dpi_change_message)


# Traceback (TypeError)
File "/opt/anaconda3/lib/python3.7/site-packages/spyder/app/mainwindow.py", line 1393, in handle_new_screen
self.show_dpi_change_message)
TypeError: 'method' object is not connected

# Fixed code
def handle_new_screen(self, screen):
    """Connect DPI signals for new screen."""
    try:
        self.screen.logicalDotsPerInchChanged.disconnect(self.show_dpi_change_message)
    except TypeError:
        # See spyder-ide/spyder#11903
        pass
    self.screen = screen
    self.screen.logicalDotsPerInchChanged.connect(self.show_dpi_change_message)
# Buggy code
def comm_channel_manager(self, comm_id, queue_message=False):
    """Use comm_channel instead of shell_channel."""
    if queue_message:
        # Send without comm_channel
        yield
        return

    if not self.comm_channel_connected():
        # Ask again for comm config
        self.remote_call()._send_comm_config()
        timeout = 10
        self._wait(
            self.comm_channel_connected,
            self._sig_channel_open,
            "Timeout while waiting for comm port.",
            timeout,
        )

    id_list = self.get_comm_id_list(comm_id)
    for comm_id in id_list:
        self._comms[comm_id]["comm"]._send_channel = self.kernel_client.comm_channel
    try:
        yield
    finally:
        for comm_id in id_list:
            self._comms[comm_id][
                "comm"
            ]._send_channel = self.kernel_client.shell_channel


# Traceback (TimeoutError)
File "C:\Users\Giovanni\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\plugin.py", line 547, in set_current_client_working_directory
shellwidget.set_cwd(directory)
File "C:\Users\Giovanni\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\widgets\shell.py", line 178, in set_cwd
self.call_kernel(interrupt=True).set_cwd(dirname)
File "C:\Users\Giovanni\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 538, in __call__
call_dict, call_data, self._comm_id)
File "C:\Users\Giovanni\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 130, in _get_call_return_value
with self.comm_channel_manager(comm_id, queue_message=not interrupt):
File "C:\Users\Giovanni\Anaconda3\lib\contextlib.py", line 112, in __enter__
return next(self.gen)
File "C:\Users\Giovanni\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 87, in comm_channel_manager
timeout)
File "C:\Users\Giovanni\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 168, in _wait
raise TimeoutError(timeout_msg)
TimeoutError: Timeout while waiting for comm port.

# Fixed code
def comm_channel_manager(self, comm_id, queue_message=False):
    """Use comm_channel instead of shell_channel."""
    if queue_message:
        # Send without comm_channel
        yield
        return

    if not self.comm_channel_connected():
        # Ask again for comm config
        self.remote_call()._send_comm_config()
        timeout = 45
        self._wait(
            self.comm_channel_connected,
            self._sig_channel_open,
            "Timeout while waiting for comm port.",
            timeout,
        )

    id_list = self.get_comm_id_list(comm_id)
    for comm_id in id_list:
        self._comms[comm_id]["comm"]._send_channel = self.kernel_client.comm_channel
    try:
        yield
    finally:
        for comm_id in id_list:
            self._comms[comm_id][
                "comm"
            ]._send_channel = self.kernel_client.shell_channel
# Buggy code
def _wait(self, condition, signal, timeout_msg, timeout):
    """
    Wait until condition() is True by running an event loop.

    signal: qt signal that should interrupt the event loop.
    timeout_msg: Meaage to display in case of a timeout.
    timeout: time in seconds before a timeout
    """
    if condition():
        return

    # Create event loop to wait with
    wait_loop = QEventLoop()
    signal.connect(wait_loop.quit)
    wait_timeout = QTimer()
    wait_timeout.setSingleShot(True)
    wait_timeout.timeout.connect(wait_loop.quit)

    # Wait until the kernel returns the value
    wait_timeout.start(timeout * 1000)
    while not condition():
        if not wait_timeout.isActive():
            signal.disconnect(wait_loop.quit)
            if not condition():
                raise TimeoutError(timeout_msg)
            return
        wait_loop.exec_()

    wait_timeout.stop()
    signal.disconnect(wait_loop.quit)


# Traceback (TimeoutError)
File "C:\Users\Giovanni\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\plugin.py", line 547, in set_current_client_working_directory
shellwidget.set_cwd(directory)
File "C:\Users\Giovanni\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\widgets\shell.py", line 178, in set_cwd
self.call_kernel(interrupt=True).set_cwd(dirname)
File "C:\Users\Giovanni\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 538, in __call__
call_dict, call_data, self._comm_id)
File "C:\Users\Giovanni\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 130, in _get_call_return_value
with self.comm_channel_manager(comm_id, queue_message=not interrupt):
File "C:\Users\Giovanni\Anaconda3\lib\contextlib.py", line 112, in __enter__
return next(self.gen)
File "C:\Users\Giovanni\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 87, in comm_channel_manager
timeout)
File "C:\Users\Giovanni\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 168, in _wait
raise TimeoutError(timeout_msg)
TimeoutError: Timeout while waiting for comm port.

# Fixed code
def _wait(self, condition, signal, timeout_msg, timeout):
    """
    Wait until condition() is True by running an event loop.

    signal: qt signal that should interrupt the event loop.
    timeout_msg: Message to display in case of a timeout.
    timeout: time in seconds before a timeout
    """
    if condition():
        return

    # Create event loop to wait with
    wait_loop = QEventLoop()
    signal.connect(wait_loop.quit)
    wait_timeout = QTimer()
    wait_timeout.setSingleShot(True)
    wait_timeout.timeout.connect(wait_loop.quit)

    # Wait until the kernel returns the value
    wait_timeout.start(timeout * 1000)
    while not condition():
        if not wait_timeout.isActive():
            signal.disconnect(wait_loop.quit)
            if not condition():
                raise TimeoutError(timeout_msg)
            return
        wait_loop.exec_()

    wait_timeout.stop()
    signal.disconnect(wait_loop.quit)
# Buggy code
def __exit__(self, exc_type, exc_val, exc_tb):
    """
    Reset the namespace.
    """
    if not self.current_namespace:
        _set_globals_locals(self.ns_globals, self.ns_locals)
    if self._previous_filename:
        self.ns_globals["__file__"] = self._previous_filename
    elif "__file__" in self.ns_globals:
        self.ns_globals.pop("__file__")
    if self._previous_main:
        sys.modules["__main__"] = self._previous_main
    elif "__main__" in sys.modules and self._reset_main:
        del sys.modules["__main__"]
    if self.filename in linecache.cache:
        linecache.cache.pop(self.filename)


# Traceback (AttributeError)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/namespacebrowser.py", line 444, in import_data
error_message = self.shellwidget.load_data(self.filename, ext)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py", line 125, in load_data
timeout=CALL_KERNEL_TIMEOUT).load_data(filename, ext)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 542, in __call__
call_dict, call_data, self._comm_id)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 114, in _get_call_return_value
call_dict, call_data, comm_id)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 420, in _get_call_return_value
return self._sync_error(reply['value'])
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 480, in _sync_error
error_wrapper.raise_error()
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 90, in raise_error
raise self.etype(self)
Exception in comms call load_data:

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 342, in _handle_remote_call
buffer['call_kwargs'])

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 353, in _remote_callback
*call_args, **call_kwargs)

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/console/kernel.py", line 257, in load_data
data[new_key] = data.pop(key)

AttributeError: 'NpzFile' object has no attribute 'pop'

# Fixed code
def __exit__(self, exc_type, exc_val, exc_tb):
    """
    Reset the namespace.
    """
    if self._previous_filename:
        self.ns_globals["__file__"] = self._previous_filename
    elif "__file__" in self.ns_globals:
        self.ns_globals.pop("__file__")

    if not self.current_namespace:
        _set_globals_locals(self.ns_globals, self.ns_locals)

    if self._previous_main:
        sys.modules["__main__"] = self._previous_main
    elif "__main__" in sys.modules and self._reset_main:
        del sys.modules["__main__"]
    if self.filename in linecache.cache:
        linecache.cache.pop(self.filename)
# Buggy code
def load_array(filename):
    try:
        name = osp.splitext(osp.basename(filename))[0]
        data = np.load(filename)
        if hasattr(data, "keys"):
            return data, None
        else:
            return {name: data}, None
    except Exception as error:
        return None, str(error)


# Traceback (AttributeError)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/namespacebrowser.py", line 444, in import_data
error_message = self.shellwidget.load_data(self.filename, ext)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py", line 125, in load_data
timeout=CALL_KERNEL_TIMEOUT).load_data(filename, ext)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 542, in __call__
call_dict, call_data, self._comm_id)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 114, in _get_call_return_value
call_dict, call_data, comm_id)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 420, in _get_call_return_value
return self._sync_error(reply['value'])
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 480, in _sync_error
error_wrapper.raise_error()
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 90, in raise_error
raise self.etype(self)
Exception in comms call load_data:

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 342, in _handle_remote_call
buffer['call_kwargs'])

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 353, in _remote_callback
*call_args, **call_kwargs)

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/console/kernel.py", line 257, in load_data
data[new_key] = data.pop(key)

AttributeError: 'NpzFile' object has no attribute 'pop'

# Fixed code
def load_array(filename):
    try:
        name = osp.splitext(osp.basename(filename))[0]
        data = np.load(filename)
        if isinstance(data, np.lib.npyio.NpzFile):
            return dict(data), None
        elif hasattr(data, "keys"):
            return data, None
        else:
            return {name: data}, None
    except Exception as error:
        return None, str(error)
# Buggy code
def fix_reference_name(name, blacklist=None):
    """Return a syntax-valid Python reference name from an arbitrary name"""
    name = "".join(re.split(r"[^0-9a-zA-Z_]", name))
    while name and not re.match(r"([a-zA-Z]+[0-9a-zA-Z_]*)$", name):
        if not re.match(r"[a-zA-Z]", name[0]):
            name = name[1:]
            continue
    name = str(name)
    if not name:
        name = "data"
    if blacklist is not None and name in blacklist:
        get_new_name = lambda index: name + ("%03d" % index)
        index = 0
        while get_new_name(index) in blacklist:
            index += 1
        name = get_new_name(index)
    return name


# Traceback (AttributeError)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/namespacebrowser.py", line 444, in import_data
error_message = self.shellwidget.load_data(self.filename, ext)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py", line 125, in load_data
timeout=CALL_KERNEL_TIMEOUT).load_data(filename, ext)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 542, in __call__
call_dict, call_data, self._comm_id)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 114, in _get_call_return_value
call_dict, call_data, comm_id)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 420, in _get_call_return_value
return self._sync_error(reply['value'])
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 480, in _sync_error
error_wrapper.raise_error()
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 90, in raise_error
raise self.etype(self)
Exception in comms call load_data:

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 342, in _handle_remote_call
buffer['call_kwargs'])

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 353, in _remote_callback
*call_args, **call_kwargs)

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/console/kernel.py", line 257, in load_data
data[new_key] = data.pop(key)

AttributeError: 'NpzFile' object has no attribute 'pop'

# Fixed code
def fix_reference_name(name, blacklist=None):
    """Return a syntax-valid Python reference name from an arbitrary name"""
    name = "".join(re.split(r"[^0-9a-zA-Z_]", name))
    while name and not re.match(r"([a-zA-Z]+[0-9a-zA-Z_]*)$", name):
        if not re.match(r"[a-zA-Z]", name[0]):
            name = name[1:]
            continue
    name = str(name)
    if not name:
        name = "data"
    if blacklist is not None and name in blacklist:
        get_new_name = lambda index: name + ("_%03d" % index)
        index = 0
        while get_new_name(index) in blacklist:
            index += 1
        name = get_new_name(index)
    return name
# Buggy code
def load_data(self, filename, ext):
    try:
        return self.call_kernel(
            interrupt=True, blocking=True, timeout=CALL_KERNEL_TIMEOUT
        ).load_data(filename, ext)
    except TimeoutError:
        msg = _("Data is too big to be loaded")
        return msg
    except UnpicklingError:
        return None


# Traceback (AttributeError)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/namespacebrowser.py", line 444, in import_data
error_message = self.shellwidget.load_data(self.filename, ext)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/widgets/namespacebrowser.py", line 125, in load_data
timeout=CALL_KERNEL_TIMEOUT).load_data(filename, ext)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 542, in __call__
call_dict, call_data, self._comm_id)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder/plugins/ipythonconsole/comms/kernelcomm.py", line 114, in _get_call_return_value
call_dict, call_data, comm_id)
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 420, in _get_call_return_value
return self._sync_error(reply['value'])
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 480, in _sync_error
error_wrapper.raise_error()
File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 90, in raise_error
raise self.etype(self)
Exception in comms call load_data:

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 342, in _handle_remote_call
buffer['call_kwargs'])

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/comms/commbase.py", line 353, in _remote_callback
*call_args, **call_kwargs)

File "/home/ok97465/anaconda3/lib/python3.7/site-packages/spyder_kernels/console/kernel.py", line 257, in load_data
data[new_key] = data.pop(key)

AttributeError: 'NpzFile' object has no attribute 'pop'

# Fixed code
def load_data(self, filename, ext):
    """Load data from a file."""
    overwrite = False
    if self.namespacebrowser.editor.var_properties:
        message = _(
            "Do you want to overwrite old "
            "variables (if any) in the namespace "
            "when loading the data?"
        )
        buttons = QMessageBox.Yes | QMessageBox.No
        result = QMessageBox.question(self, _("Data loading"), message, buttons)
        overwrite = result == QMessageBox.Yes
    try:
        return self.call_kernel(
            interrupt=True, blocking=True, timeout=CALL_KERNEL_TIMEOUT
        ).load_data(filename, ext, overwrite=overwrite)
    except TimeoutError:
        msg = _("Data is too big to be loaded")
        return msg
    except UnpicklingError:
        return None
# Buggy code
def __refresh_statusbar(self, index):
    """Refreshing statusbar widgets"""
    finfo = self.data[index]
    self.encoding_changed.emit(finfo.encoding)
    # Refresh cursor position status:
    line, index = finfo.editor.get_cursor_line_column()
    self.sig_editor_cursor_position_changed.emit(line, index)


# Traceback (IndexError)
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\plugin.py", line 1901, in load
self.switch_to_plugin()
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\plugin.py", line 1437, in switch_to_plugin
super(Editor, self).switch_to_plugin()
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\api\plugins.py", line 355, in switch_to_plugin
super(BasePluginWidget, self)._switch_to_plugin()
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\base.py", line 290, in _switch_to_plugin
self._visibility_changed(True)
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\plugin.py", line 346, in _visibility_changed
SpyderPluginWidget._visibility_changed(self, enable)
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\base.py", line 388, in _visibility_changed
self.refresh_plugin()
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\plugin.py", line 360, in refresh_plugin
editorstack.refresh()
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 2404, in refresh
self._refresh_outlineexplorer(index, update=False)
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 2283, in _refresh_outlineexplorer
finfo = self.data[index]
IndexError: list index out of range

# Fixed code
def __refresh_statusbar(self, index):
    """Refreshing statusbar widgets"""
    if self.data and len(self.data) > index:
        finfo = self.data[index]
        self.encoding_changed.emit(finfo.encoding)
        # Refresh cursor position status:
        line, index = finfo.editor.get_cursor_line_column()
        self.sig_editor_cursor_position_changed.emit(line, index)
# Buggy code
def __refresh_readonly(self, index):
    finfo = self.data[index]
    read_only = not QFileInfo(finfo.filename).isWritable()
    if not osp.isfile(finfo.filename):
        # This is an 'untitledX.py' file (newly created)
        read_only = False
    finfo.editor.setReadOnly(read_only)
    self.readonly_changed.emit(read_only)


# Traceback (IndexError)
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\plugin.py", line 1901, in load
self.switch_to_plugin()
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\plugin.py", line 1437, in switch_to_plugin
super(Editor, self).switch_to_plugin()
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\api\plugins.py", line 355, in switch_to_plugin
super(BasePluginWidget, self)._switch_to_plugin()
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\base.py", line 290, in _switch_to_plugin
self._visibility_changed(True)
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\plugin.py", line 346, in _visibility_changed
SpyderPluginWidget._visibility_changed(self, enable)
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\base.py", line 388, in _visibility_changed
self.refresh_plugin()
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\plugin.py", line 360, in refresh_plugin
editorstack.refresh()
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 2404, in refresh
self._refresh_outlineexplorer(index, update=False)
File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 2283, in _refresh_outlineexplorer
finfo = self.data[index]
IndexError: list index out of range

# Fixed code
def __refresh_readonly(self, index):
    if self.data and len(self.data) > index:
        finfo = self.data[index]
        read_only = not QFileInfo(finfo.filename).isWritable()
        if not osp.isfile(finfo.filename):
            # This is an 'untitledX.py' file (newly created)
            read_only = False
        finfo.editor.setReadOnly(read_only)
        self.readonly_changed.emit(read_only)
# Buggy code
def set_data(self, data):
    """Set table data"""
    if data is not None:
        self.source_model.set_data(data, self.dictfilter)
        self.sortByColumn(0, Qt.AscendingOrder)


# Traceback (KeyError)
Exception in comms call remove_value:
File "C:\Users\gianf\anaconda\lib\site-packages\spyder_kernels\comms\commbase.py", line 342, in _handle_remote_call
buffer['call_kwargs'])
File "C:\Users\gianf\anaconda\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
*call_args, **call_kwargs)
File "C:\Users\gianf\anaconda\lib\site-packages\spyder_kernels\console\kernel.py", line 234, in remove_value
ns.pop(name)
KeyError: 'ScalarType'

# Fixed code
def set_data(self, data):
    """Set table data"""
    if data is not None:
        self.source_model.set_data(data, self.dictfilter)
        self.source_model.reset()
        self.sortByColumn(0, Qt.AscendingOrder)
# Buggy code
def renamed(self, source, dest):
    """
    Propagate file rename to editor stacks and autosave component.

    This function is called when a file is renamed in the file explorer
    widget or the project explorer.
    """
    filename = osp.abspath(to_text_string(source))
    index = self.editorstacks[0].has_filename(filename)
    if index is not None:
        for editorstack in self.editorstacks:
            editorstack.rename_in_data(filename, new_filename=to_text_string(dest))
    self.editorstacks[0].autosave.file_renamed(filename, to_text_string(dest))


# Traceback (KeyError)
File "C:\Users\Tulpar\Anaconda3\lib\site-packages\spyder\plugins\editor\plugin.py", line 2108, in renamed
filename, to_text_string(dest))
File "C:\Users\Tulpar\Anaconda3\lib\site-packages\spyder\plugins\editor\utils\autosave.py", line 385, in file_renamed
old_hash = self.file_hashes[old_name]
KeyError: 'C:\\ferfiles\\mobilenetv2.py'

# Fixed code
def renamed(self, source, dest):
    """
    Propagate file rename to editor stacks and autosave component.

    This function is called when a file is renamed in the file explorer
    widget or the project explorer. The file may not be opened in the
    editor.
    """
    filename = osp.abspath(to_text_string(source))
    index = self.editorstacks[0].has_filename(filename)
    if index is not None:
        for editorstack in self.editorstacks:
            editorstack.rename_in_data(filename, new_filename=to_text_string(dest))
        self.editorstacks[0].autosave.file_renamed(filename, to_text_string(dest))
# Buggy code
def rename_file(self, fname):
    """Rename file"""
    path, valid = QInputDialog.getText(
        self, _("Rename"), _("New name:"), QLineEdit.Normal, osp.basename(fname)
    )
    if valid:
        path = osp.join(osp.dirname(fname), to_text_string(path))
        if path == fname:
            return
        if osp.exists(path):
            if (
                QMessageBox.warning(
                    self,
                    _("Rename"),
                    _(
                        "Do you really want to rename <b>%s</b> and "
                        "overwrite the existing file <b>%s</b>?"
                    )
                    % (osp.basename(fname), osp.basename(path)),
                    QMessageBox.Yes | QMessageBox.No,
                )
                == QMessageBox.No
            ):
                return
        try:
            misc.rename_file(fname, path)
            if osp.isfile(fname):
                self.sig_renamed.emit(fname, path)
            else:
                self.sig_renamed_tree.emit(fname, path)
            return path
        except EnvironmentError as error:
            QMessageBox.critical(
                self,
                _("Rename"),
                _("<b>Unable to rename file <i>%s</i></b><br><br>Error message:<br>%s")
                % (osp.basename(fname), to_text_string(error)),
            )


# Traceback (KeyError)
File "C:\Users\Tulpar\Anaconda3\lib\site-packages\spyder\plugins\editor\plugin.py", line 2108, in renamed
filename, to_text_string(dest))
File "C:\Users\Tulpar\Anaconda3\lib\site-packages\spyder\plugins\editor\utils\autosave.py", line 385, in file_renamed
old_hash = self.file_hashes[old_name]
KeyError: 'C:\\ferfiles\\mobilenetv2.py'

# Fixed code
def rename_file(self, fname):
    """Rename file"""
    path, valid = QInputDialog.getText(
        self, _("Rename"), _("New name:"), QLineEdit.Normal, osp.basename(fname)
    )
    if valid:
        path = osp.join(osp.dirname(fname), to_text_string(path))
        if path == fname:
            return
        if osp.exists(path):
            if (
                QMessageBox.warning(
                    self,
                    _("Rename"),
                    _(
                        "Do you really want to rename <b>%s</b> and "
                        "overwrite the existing file <b>%s</b>?"
                    )
                    % (osp.basename(fname), osp.basename(path)),
                    QMessageBox.Yes | QMessageBox.No,
                )
                == QMessageBox.No
            ):
                return
        try:
            misc.rename_file(fname, path)
            if osp.isfile(path):
                self.sig_renamed.emit(fname, path)
            else:
                self.sig_renamed_tree.emit(fname, path)
            return path
        except EnvironmentError as error:
            QMessageBox.critical(
                self,
                _("Rename"),
                _("<b>Unable to rename file <i>%s</i></b><br><br>Error message:<br>%s")
                % (osp.basename(fname), to_text_string(error)),
            )
# Buggy code
def set_cwd(self, dirname):
    """Set shell current working directory."""
    # Replace single for double backslashes on Windows
    if os.name == "nt":
        dirname = dirname.replace("\\", "\\\\")

    if self.ipyclient.hostname is None:
        self.call_kernel(interrupt=True).set_cwd(dirname)
        self._cwd = dirname


# Traceback (FileNotFoundError)
Exception in comms call set_cwd:
File "C:\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 342, in _handle_remote_call
buffer['call_kwargs'])
File "C:\Anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py", line 353, in _remote_callback
*call_args, **call_kwargs)
File "C:\Anaconda3\lib\site-packages\spyder_kernels\console\kernel.py", line 352, in set_cwd
os.chdir(dirname)
FileNotFoundError: [Errno 2] The specified path is invalid: '\\\\\\\\fs01\\\\users\\\\ora\\\\Python Scripts\\\\HS_Scanner'
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 set_cwd(self, dirname):
    """Set shell current working directory."""
    if os.name == "nt":
        # Use normpath instead of replacing '\' with '\\'
        # See spyder-ide/spyder#10785
        dirname = osp.normpath(dirname)

    if self.ipyclient.hostname is None:
        self.call_kernel(interrupt=True).set_cwd(dirname)
        self._cwd = dirname
# Buggy code
def tab_pressed(self, event):
    """Method called when a tab from a QTabBar has been pressed."""
    self.from_index = self.dock_tabbar.tabAt(event.pos())
    self.dock_tabbar.setCurrentIndex(self.from_index)

    if event.button() == Qt.RightButton:
        if self.from_index == -1:
            self.show_nontab_menu(event)
        else:
            self.show_tab_menu(event)


# Traceback (AttributeError)
File "/Users/luismireles/opt/anaconda3/envs/K37/lib/python3.7/site-packages/spyder/widgets/dock.py", line 43, in eventFilter
self.tab_pressed(event)
File "/Users/luismireles/opt/anaconda3/envs/K37/lib/python3.7/site-packages/spyder/widgets/dock.py", line 52, in tab_pressed
if event.button() == Qt.RightButton:
AttributeError: 'QContextMenuEvent' object has no attribute 'button'

# Fixed code
def tab_pressed(self, event):
    """Method called when a tab from a QTabBar has been pressed."""
    self.from_index = self.dock_tabbar.tabAt(event.pos())
    self.dock_tabbar.setCurrentIndex(self.from_index)

    try:
        if event.button() == Qt.RightButton:
            if self.from_index == -1:
                self.show_nontab_menu(event)
            else:
                self.show_tab_menu(event)
    except AttributeError:
        # Needed to avoid an error when generating the
        # context menu on top of the tab.
        # See spyder-ide/spyder#11226
        pass
# Buggy code
def display_help(self, help_text, clicked):
    editor = self.get_current_editor()
    if clicked:
        name = editor.get_last_hover_word()
    else:
        name = editor.get_current_word()

    editor.sig_display_object_info.disconnect(self.display_help)
    self.help.switch_to_editor_source()
    self.send_to_help(name, help_text, force=True)


# Traceback (TypeError)
File "/home/shivendra/anaconda3/lib/python3.7/site-packages/spyder/plugins/editor/widgets/editor.py", line 1068, in display_help
editor.sig_display_object_info.disconnect(self.display_help)
TypeError: disconnect() failed between 'sig_display_object_info' and 'display_help'

# Fixed code
def display_help(self, help_text, clicked):
    editor = self.get_current_editor()
    if clicked:
        name = editor.get_last_hover_word()
    else:
        name = editor.get_current_word()

    try:
        editor.sig_display_object_info.disconnect(self.display_help)
    except TypeError:
        # Needed to prevent an error after some time in idle.
        # See spyder-ide/spyder#11228
        pass
    self.help.switch_to_editor_source()
    self.send_to_help(name, help_text, force=True)
# Buggy code
def get_previous_config_fpath(self):
    """
    Override method.

    Return the last configuration file used if found.
    """
    fpath = self.get_config_fpath()
    previous_paths = [
        # >= 51.0.0
        fpath,
        # < 51.0.0
        os.path.join(get_conf_path(), "spyder.ini"),
    ]
    for fpath in previous_paths:
        if osp.isfile(fpath):
            break

    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_previous_config_fpath(self):
    """
    Override method.

    Return the last configuration file used if found.
    """
    fpath = self.get_config_fpath()

    # We don't need to add the contents of the old spyder.ini to
    # the configuration of external plugins. This was the cause
    # of  part two (the shortcut conflicts) of issue
    # spyder-ide/spyder#11132
    if self._external_plugin:
        previous_paths = [fpath]
    else:
        previous_paths = [
            # >= 51.0.0
            fpath,
            # < 51.0.0
            os.path.join(get_conf_path(), "spyder.ini"),
        ]

    for fpath in previous_paths:
        if osp.isfile(fpath):
            break

    return fpath