internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: spyder-ide/spyder

Issue:
fix ArrayEditor under PyQt5
hi,

1136a1e08e74abb65d77dbea452479c02aba454f introduced a bug, as `QItemSelection` and `QItemSelectionRange` are in QtCore now.

fix ArrayEditor under PyQt5
hi,

1136a1e08e74abb65d77dbea452479c02aba454f introduced a bug, as `QItemSelection` and `QItemSelectionRange` are in QtCore now.



Discussion:

Resolving patch:
diff --git a/spyderlib/qt/QtCore.py b/spyderlib/qt/QtCore.py
--- a/spyderlib/qt/QtCore.py
+++ b/spyderlib/qt/QtCore.py
@@ -21,6 +21,8 @@
     from PyQt4.QtCore import pyqtSlot as Slot                 # analysis:ignore
     from PyQt4.QtCore import pyqtProperty as Property         # analysis:ignore
     from PyQt4.QtCore import QT_VERSION_STR as __version__    # analysis:ignore
+
+    from PyQt4.QtGui import QItemSelection, QItemSelectionRange  # analysis:ignore
 else:
     import PySide.QtCore
     __version__ = PySide.QtCore.__version__                   # analysis:ignore
diff --git a/spyderlib/qt/QtGui.py b/spyderlib/qt/QtGui.py
--- a/spyderlib/qt/QtGui.py
+++ b/spyderlib/qt/QtGui.py
@@ -17,6 +17,7 @@
     from PyQt4.Qt import QKeySequence, QTextCursor            # analysis:ignore
     from PyQt4.QtGui import *                                 # analysis:ignore
     QStyleOptionViewItem = QStyleOptionViewItemV4             # analysis:ignore
+    del QItemSelection, QItemSelectionRange                   # analysis:ignore
 else:
     from PySide.QtGui import *                                # analysis:ignore
     QStyleOptionViewItem = QStyleOptionViewItemV4             # analysis:ignore
diff --git a/spyderlib/widgets/varexp/arrayeditor.py b/spyderlib/widgets/varexp/arrayeditor.py
--- a/spyderlib/widgets/varexp/arrayeditor.py
+++ b/spyderlib/widgets/varexp/arrayeditor.py
@@ -21,9 +21,9 @@
                                 QMessageBox, QPushButton, QInputDialog, QMenu,
                                 QApplication, QKeySequence, QLabel, QComboBox,
                                 QSpinBox, QStackedWidget, QWidget, QVBoxLayout,
-                                QAbstractItemDelegate, QItemSelection,
-                                QItemSelectionRange)
-from spyderlib.qt.QtCore import (Qt, QModelIndex, QAbstractTableModel, Slot)
+                                QAbstractItemDelegate)
+from spyderlib.qt.QtCore import (Qt, QModelIndex, QAbstractTableModel, Slot,
+                                 QItemSelection, QItemSelectionRange)
 
 from spyderlib.qt.compat import to_qvariant, from_qvariant
 import spyderlib.utils.icon_manager as ima


Test patch:
Repository: spyder-ide/spyder

Issue:
F5 (run) saves editor file, but F10 (profile) does not
_From [dave.lin...@gmail.com](https://code.google.com/u/107110792395568123171/) on 2014-03-21T13:52:30Z_

Spyder Version:  2.2.5
Python Version:  2.7.6
Qt Version    :  4.8.4, PyQt4 (API v2) 4.9.6 on Windows
pyflakes >=0.5.0:  None (OK)
pep8 >=0.6      :  None (NOK)
IPython >=0.13  :  1.1.0 (OK)
rope >=0.9.2    :  0.9.4 (OK)
sphinx >=0.6.6  :  1.2.1 (OK)
matplotlib >=1.0:  1.3.1 (OK)
sympy >=0.7.0   :  0.7.4.1 (OK)
pylint >=0.25   :  1.0.0 (OK) 

What steps will reproduce the problem?
1. Edit the source file
   1. Hit F5 - note that file is saved, then new version is run.
   2. Edit the source file (again)
   3. Hit F10 - note that the file is NOT saved, the old version is run. What is the expected output? What do you see instead? I'd expect F5 and F10 to do the same thing re saving the file.  I think the current F5 behavior is better (save file, then run). 

Please provide any additional information below

.

_Original issue: http://code.google.com/p/spyderlib/issues/detail?id=1761_



Discussion:

Resolving patch:
diff --git a/spyderplugins/p_profiler.py b/spyderplugins/p_profiler.py
--- a/spyderplugins/p_profiler.py
+++ b/spyderplugins/p_profiler.py
@@ -120,7 +120,8 @@ def apply_plugin_settings(self, options):
     #------ Public API ---------------------------------------------------------        
     def run_profiler(self):
         """Run profiler"""
-        self.analyze(self.main.editor.get_current_filename())
+        if self.main.editor.save():
+            self.analyze(self.main.editor.get_current_filename())
 
     def analyze(self, filename):
         """Reimplement analyze method"""


Test patch:
Repository: spyder-ide/spyder

Issue:
Option  'Automatic insertion of parentheses, braces and brackets' has issues when un-checked
We can't type `print ("Hello Word") , with Spyder 3 trunk of October 24th morning and 'Automatic insertion of parentheses, braces and brackets' unchecked

issue is on Winpython3.4.3.6 at least 
discovered by @ezbentley  https://github.com/winpython/winpython/issues/193



Discussion:

Resolving patch:
diff --git a/spyderlib/widgets/sourcecode/codeeditor.py b/spyderlib/widgets/sourcecode/codeeditor.py
--- a/spyderlib/widgets/sourcecode/codeeditor.py
+++ b/spyderlib/widgets/sourcecode/codeeditor.py
@@ -2603,6 +2603,8 @@ def keyPressEvent(self, event):
             self.hide_completion_widget()
             if self.close_parentheses_enabled:
                 self.handle_close_parentheses(text)
+            else:
+                self.insert_text(text)
         elif text in ('[', '{') and not self.has_selected_text() \
           and self.close_parentheses_enabled:
             s_trailing_text = self.get_text('cursor', 'eol').strip()


Test patch:
Repository: spyder-ide/spyder

Issue:
Automatically set working directory in console
The current behavior of the current working directory text field in the menu bar might be confusing, especially to beginners and/or people coming from MATLAB. Currently, the working directory is not automatically updated in the console when the working directory is changed in the menu bar (either by directly entering a new path, or navigating up, or by choosing a specific directory). Instead, the user has to click the dedicated "Set as current console's working directory" button.

I suggest to change this behavior such that changes in the working directory set in the menu bar are always automatically propagated to the current (or even all) console.



Discussion:

Resolving patch:
diff --git a/spyderlib/plugins/workingdirectory.py b/spyderlib/plugins/workingdirectory.py
--- a/spyderlib/plugins/workingdirectory.py
+++ b/spyderlib/plugins/workingdirectory.py
@@ -339,6 +339,7 @@ def chdir(self, directory=None, browsing_history=False,
         self.refresh_plugin()
         if refresh_explorer:
             self.set_explorer_cwd.emit(directory)
+            self.set_as_current_console_wd()
         self.refresh_findinfiles.emit()
     
     @Slot()


Test patch:
Repository: spyder-ide/spyder

Issue:
File in Project Explorer is being executed(?) on dbl-click
WinPython-64bit-3.4.3.4
Double-clicking on a file with the following content opens python console with "ImportError: No module named PyQt4"

``` python
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 26 11:53:52 2015

@author: автор
"""

from PyQt4 import QtGui
from general import COL, showConsole
from context import *

railways = {"Октябрьская Ж.Д.": 1, "Октябрьская": 1,
      "Калининградская Ж.Д.": 2, "Калининградская": 2,
      "Московская Ж.Д.": 3, "Московская": 3,
      "Горьковская Ж.Д.": 4, "Горьковская": 4,
      "Северная Ж.Д.": 5, "Северная": 5,
      "Северо-Кавказская Ж.Д.": 6, "Северо-Кавказская": 6,
      "Юго-Восточная Ж.Д.": 7, "Юго-Восточная": 7,
      "Приволжская Ж.Д.": 8, "Приволжская": 8,
      "Куйбышевская Ж.Д.": 9, "Куйбышевская": 9,
      "Свердловская Ж.Д.": 10, "Свердловская": 10,
      "Южно-Уральская Ж.Д.": 11, "Южно-Уральская": 11,
      "Западно-Сибирская Ж.Д.": 12, "Западно-Сибирская": 12,
      "Красноярская Ж.Д.": 13, "Красноярская": 13,
      "Восточно-Сибирская Ж.Д.": 14, "Восточно-Сибирская": 14,
      "Забайкальская Ж.Д.": 15, "Забайкальская": 15,
      "Дальневосточная Ж.Д.": 16, "Дальневосточная": 16}
```



Discussion:
Projects are being reworked for our next major version, i.e. Spyder 3.0, which is going to be released by the end of the year.


Resolving patch:
diff --git a/spyderlib/utils/encoding.py b/spyderlib/utils/encoding.py
--- a/spyderlib/utils/encoding.py
+++ b/spyderlib/utils/encoding.py
@@ -15,7 +15,7 @@
 import os
 import locale
 import sys
-from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF32
+from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF32, getincrementaldecoder
 
 # Local imports
 from spyderlib.py3compat import (is_string, to_text_string, is_binary_string,
@@ -243,13 +243,16 @@ def is_text_file(filename):
             for bom in [BOM_UTF8, BOM_UTF16, BOM_UTF32]:
                 if chunk.startswith(bom):
                     return True
-            chunk = chunk.decode('utf-8')
+
+            decoder = getincrementaldecoder('utf-8')()
             while 1:
+                is_final = len(chunk) < CHUNKSIZE
+                chunk = decoder.decode(chunk, final=is_final)
                 if '\0' in chunk: # found null byte
                     return False
-                if len(chunk) < CHUNKSIZE:
+                if is_final:
                     break # done
-                chunk = fid.read(CHUNKSIZE).decode('utf-8')
+                chunk = fid.read(CHUNKSIZE)
         except UnicodeDecodeError:
             return False
         except Exception:


Test patch:
Repository: spyder-ide/spyder

Issue:
Control+C should not copy if it has nothing selected on the editor
# Description

Select something on the editor and `Ctrl+C` it... then with nothing selected accidentally typing `Ctrl+C` will replace the content of the clipboard with an empty string... this is annoying.

If nothing is selected, the behavior should be to no put an empty string in the clipboard...



Discussion:
@julianrolon


Resolving patch:
diff --git a/spyderlib/widgets/sourcecode/base.py b/spyderlib/widgets/sourcecode/base.py
--- a/spyderlib/widgets/sourcecode/base.py
+++ b/spyderlib/widgets/sourcecode/base.py
@@ -492,7 +492,8 @@ def copy(self):
         Reimplement Qt method
         Copy text to clipboard with correct EOL chars
         """
-        QApplication.clipboard().setText(self.get_selected_text())
+        if self.get_selected_text():
+            QApplication.clipboard().setText(self.get_selected_text())
     
     def toPlainText(self):
         """


Test patch:
Repository: spyder-ide/spyder

Issue:
Is there a way to modify the main window title?
We are working in a multi-user environment with multiple instances of spyder opened. It would be convenient to show the session name (or any string) in the window title. Is there already a method to to this? If not, I can add a command line option to enable this.



Discussion:
Hi @eendebakpt, could you elaborate a bit more?

Right now the title of my spyder window is `Spyder (Python 3.4)`. I would like to be able to set this (from either the command line or using a script) to something like `Spyder (Python 3.4): current user "Pieter"`

I meant context for 

> multi-user environment with multiple instances of spyder opened

Not the actual implementation (that I understood)

I fail to see how this "work environment works"

@ccordoba12 ?

@peendebak and @eendebakpt, we're glad to accept a pull request to help you improve your workflow (although as @goanpeca said, we don't understand too well how that works :-).

Command line options are defined here:

https://github.com/spyder-ide/spyder/blob/master/spyderlib/app/cli_options.py

and the window title is set here:

https://github.com/spyder-ide/spyder/blob/master/spyderlib/app/spyder.py#L432

Would it help to add the current focused filename in the title ?

Otherwise I guess that a plugin coud be made to fit your specific need. They are revamped for spyder 3.0 and it should be easier to manage them.


Resolving patch:
diff --git a/spyderlib/app/cli_options.py b/spyderlib/app/cli_options.py
--- a/spyderlib/app/cli_options.py
+++ b/spyderlib/app/cli_options.py
@@ -37,5 +37,7 @@ def get_options():
     parser.add_option('--profile', action='store_true', default=False,
                       help="Profile mode (internal test, "
                            "not related with Python profiling)")
+    parser.add_option('--window-title', type=str, default=None,
+                      help="String to show in the main window title")
     options, args = parser.parse_args()
     return options, args
diff --git a/spyderlib/app/spyder.py b/spyderlib/app/spyder.py
--- a/spyderlib/app/spyder.py
+++ b/spyderlib/app/spyder.py
@@ -439,6 +439,9 @@ def signal_handler(signum, frame=None):
                                                sys.version_info[1])
         if DEBUG:
             title += " [DEBUG MODE %d]" % DEBUG
+        if options.window_title is not None:
+            title += ' ' + options.window_title
+            
         self.setWindowTitle(title)
         resample = os.name != 'nt'
         icon = ima.icon('spyder', resample=resample)


Test patch:
Repository: spyder-ide/spyder

Issue:
Local variable 'backends' referenced before assignment when starting IPython kernel
## Description of your problem

**What steps will reproduce the problem?**
1. Install 3.0.0b3 as per instructions in #2724
2. Start spyder

**What is the expected output? What do you see instead?**

``` python
Traceback (most recent call last):
  File "/users/nicolas/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/start_ipython_kernel.py", line 189, in <module>
    ipk_temp.config = kernel_config()
  File "/users/nicolas/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/start_ipython_kernel.py", line 95, in kernel_config
    if backends[backend_o] == 'inline':
UnboundLocalError: local variable 'backends' referenced before assignment
```

**Please provide any additional information below**
## Versions and main components
- Spyder Version: 3.0.0b3
- Python Version: Python 2.7.11 (anaconda)
- Operating system: OSX 10.11
## Dependencies

jedi >=0.8.1    :  0.9.0 (OK)
matplotlib >=1.0:  1.5.1 (OK)
nbconvert >=4.0 :  4.1.0 (OK)
numpy >=1.7     :  1.10.4 (OK)
pandas >=0.13.1 :  0.18.0 (OK)
pep8 >=0.6      :  1.7.0 (OK)
psutil >=0.3    :  4.1.0 (OK)
pyflakes >=0.5.0:  1.1.0 (OK)
pygments >=1.6  :  2.1.1 (OK)
pylint >=0.25   :  1.5.4 (OK)
qtconsole >=4.0 :  4.2.0 (OK)
rope >=0.9.4    :  0.9.4 (OK)
sphinx >=0.6.6  :  1.3.5 (OK)
sympy >=0.7.3   :  1.0 (OK)



Discussion:

Resolving patch:
diff --git a/spyderlib/widgets/externalshell/start_ipython_kernel.py b/spyderlib/widgets/externalshell/start_ipython_kernel.py
--- a/spyderlib/widgets/externalshell/start_ipython_kernel.py
+++ b/spyderlib/widgets/externalshell/start_ipython_kernel.py
@@ -92,7 +92,7 @@ def kernel_config():
                                          "%matplotlib {0}".format(mpl_backend))
 
         # Inline backend configuration
-        if backends[backend_o] == 'inline':
+        if mpl_backend == 'inline':
            # Figure format
            format_o = CONF.get('ipython_console',
                                'pylab/inline/figure_format', 0)


Test patch:
Repository: spyder-ide/spyder

Issue:
Variable explorer - Sequence break with wrong mapping
the Name, Type, Size mapped wrong to each other after click each label name ( for order by), only the first python execution get the correct value. next time need to delete all content in variable explorer and re-run the code. 
please refer to the attached document for detail screen-shot.
[Spyder issue - Variable explorer .docx](https://github.com/spyder-ide/spyder/files/137574/Spyder.issue.-.Variable.explorer.docx)



Discussion:
Thanks for the report. Here is how I can reproduce it. 

Give the following commands in the console:

``` python
a = 'b'
x = [1, 2]
integers = list(range(1, 151))
evens = [n for n in integers if n % 2 == 0]
```

Open the variable explorer (everything looks fine). In the variable explorer, click on `Type` to sort that column. The variable explorer now says that `x` has length 150. In fact, `x` has length 2. The value is displayed correctly.


Resolving patch:
diff --git a/spyderlib/widgets/variableexplorer/utils.py b/spyderlib/widgets/variableexplorer/utils.py
--- a/spyderlib/widgets/variableexplorer/utils.py
+++ b/spyderlib/widgets/variableexplorer/utils.py
@@ -214,12 +214,18 @@ def is_editable_type(value):
 #==============================================================================
 # Sorting
 #==============================================================================
-def sort_against(lista, listb, reverse=False):
-    """Arrange lista items in the same order as sorted(listb)"""
+def sort_against(list1, list2, reverse=False):
+    """
+    Arrange items of list1 in the same order as sorted(list2).
+
+    In other words, apply to list1 the permutation which takes list2 
+    to sorted(list2, reverse).
+    """
     try:
-        return [item for _, item in sorted(zip(listb, lista), reverse=reverse)]
+        return [item for _, item in 
+                sorted(zip(list2, list1), key=lambda x: x[0], reverse=reverse)]
     except:
-        return lista
+        return list1
 
 
 def unsorted_unique(lista):


Test patch:
diff --git a/spyderlib/widgets/variableexplorer/tests/test_utils.py b/spyderlib/widgets/variableexplorer/tests/test_utils.py
new file mode 100644
--- /dev/null
+++ b/spyderlib/widgets/variableexplorer/tests/test_utils.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright © 2009- The Spyder Development Team
+# Licensed under the terms of the MIT License
+
+"""
+Tests for utils.py
+"""
+
+# Third party imports
+import pytest
+
+# Local imports
+from spyderlib.widgets.variableexplorer.utils import sort_against
+
+
+# --- Tests
+# -----------------------------------------------------------------------------
+def test_sort_against():
+    lista = [5, 6, 7]
+    listb = [2, 3, 1]
+    res = sort_against(lista, listb)
+    assert res == [7, 5, 6]
+
+def test_sort_against_is_stable():
+    lista = [3, 0, 1]
+    listb = [1, 1, 1]
+    res = sort_against(lista, listb)
+    assert res == lista
+    
+
+if __name__ == "__main__":
+    pytest.main()
Repository: spyder-ide/spyder

Issue:
QApplication is used from QtGui instead of QtWidgets in app/spyder.py
The following lines in `initialize()` in `spyderlib/app/spyder.py` (dev version, revision 48c96725) look rather suspicious to me:

``` python
    #----Monkey patching PyQt4.QtGui.QApplication
    class FakeQApplication(QApplication):
        """Spyder's fake QApplication"""
        def __init__(self, args):
            self = app  # analysis:ignore
        @staticmethod
        def exec_():
            """Do nothing because the Qt mainloop is already running"""
            pass
    from qtpy import QtGui
    QtGui.QApplication = FakeQApplication
```

After the transition to qt5, QApplication resides in QtWidgets, so should the final line be `QtWidgets.QApplication = FakeQApplication`? I don't know the reason why this code is included, so I can't do more than flag up the issue.



Discussion:
Thanks for noticing @jitseniesen! I'll take a look at it :-)


Resolving patch:
diff --git a/spyderlib/app/spyder.py b/spyderlib/app/spyder.py
--- a/spyderlib/app/spyder.py
+++ b/spyderlib/app/spyder.py
@@ -88,7 +88,7 @@
 from qtpy import QtSvg  # analysis:ignore
 
 # Avoid a bug in Qt: https://bugreports.qt.io/browse/QTBUG-46720
-from qtpy import QtWebEngineWidgets
+from qtpy import QtWebEngineWidgets  # analysis:ignore
 
 
 #==============================================================================
@@ -126,7 +126,6 @@
 from spyderlib.app.cli_options import get_options
 from spyderlib import dependencies
 from spyderlib.config.ipython import QTCONSOLE_INSTALLED
-from spyderlib.config.user import NoDefault
 from spyderlib.py3compat import (getcwd, is_text_string, to_text_string,
                                  PY3, qbytearray_to_str, u, configparser as cp)
 from spyderlib.utils import encoding, programs
@@ -2888,7 +2887,7 @@ def initialize():
     # possible
     app = qapplication()
 
-    #----Monkey patching PyQt4.QtGui.QApplication
+    #----Monkey patching QApplication
     class FakeQApplication(QApplication):
         """Spyder's fake QApplication"""
         def __init__(self, args):
@@ -2897,8 +2896,8 @@ def __init__(self, args):
         def exec_():
             """Do nothing because the Qt mainloop is already running"""
             pass
-    from qtpy import QtGui
-    QtGui.QApplication = FakeQApplication
+    from qtpy import QtWidgets
+    QtWidgets.QApplication = FakeQApplication
 
     #----Monkey patching rope
     try:


Test patch:
Repository: spyder-ide/spyder

Issue:
"Quit Spyder" menu entry doesn't work in 3.0.0b4 (OS X 10.11)
## Description of your problem

**What steps will reproduce the problem?**
1. Open spyder 3.0.0beta4 (anaconda installation on OS X 10.11.5)
2. Attempt to close using toolbar `python | Quit Spyder option`
3. Nothing happens
## Versions and main components
- Spyder Version: 3.0.0beta4
- Python Version: Python 2.7.11 |Continuum Analytics, Inc.| (default, Dec  6 2015, 18:57:58)
- Operating system: OS X 10.11.5
## Dependencies

jedi >=0.8.1     :  0.9.0 (OK)
matplotlib >=1.0 :  1.4.3 (OK)
nbconvert >=4.0  :  4.2.0 (OK)
numpy >=1.7      :  1.9.2 (OK)
pandas >=0.13.1  :  None (NOK)
pep8 >=0.6       :  1.7.0 (OK)
psutil >=0.3     :  4.3.0 (OK)
pyflakes >=0.5.0 :  1.2.3 (OK)
pygments >=2.0   :  2.1.3 (OK)
qtconsole >=4.2.0:  4.2.1 (OK)
rope >=0.9.4     :  0.9.4 (OK)
sphinx >=0.6.6   :  1.4.1 (OK)
sympy >=0.7.3    :  None (NOK)



Discussion:
What is your PyQt version?

@ccordoba12 here you go, `PyQt 5.6`:
![spyder300b4](https://cloud.githubusercontent.com/assets/3229632/16843662/05fc0ec2-4997-11e6-845d-a2980bea10f6.png)

I can confirm the same problem using the same configuration (except under Python 3.5 64 bit on OS X).  Cmd-Q doesn't work either, looks like the menu item may not be connected to the command to quit.

Can also confirm this is an issue for me.  Using Python 2.7 64 bit on OS X, with PyQt version 5.6


Resolving patch:
diff --git a/spyderlib/app/spyder.py b/spyderlib/app/spyder.py
--- a/spyderlib/app/spyder.py
+++ b/spyderlib/app/spyder.py
@@ -323,7 +323,7 @@ def signal_handler(signum, frame=None):
                                         triggered=self.load_session,
                                         tip=_("Load Spyder session"))
         self.save_session_action = create_action(self,
-                                        _("Save session and quit..."),
+                                        _("Save session..."),
                                         None, ima.icon('filesaveas'),
                                         triggered=self.save_session,
                                         tip=_("Save current session "
diff --git a/spyderlib/plugins/editor.py b/spyderlib/plugins/editor.py
--- a/spyderlib/plugins/editor.py
+++ b/spyderlib/plugins/editor.py
@@ -777,8 +777,8 @@ def get_plugin_actions(self):
         self.register_shortcut(debug_return_action, "_", "Debug Step Return",
                                add_sc_to_tip=True)
 
-        debug_exit_action = create_action(self, _("Exit"),
-               icon=ima.icon('stop_debug'), tip=_("Exit Debug"),
+        debug_exit_action = create_action(self, _("Stop"),
+               icon=ima.icon('stop_debug'), tip=_("Stop debugging"),
                triggered=lambda: self.debug_command("exit"))
         self.register_shortcut(debug_exit_action, "_", "Debug Exit",
                                add_sc_to_tip=True)


Test patch: