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

Issue:
test failure in arg_split on windows
arg_split has a failing test on windows. 

```
ERROR: Ensure that argument lines are correctly split like in a shell.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\python\ipydevel\VENV\py27\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "C:\python\ipydevel\VENV\py27\lib\site-packages\ipython-0.13.dev-py2.7.egg\IPython\testing\decorators.py", line 228, in skipper_func
    return f(*args, **kwargs)
  File "C:\python\ipydevel\VENV\py27\lib\site-packages\ipython-0.13.dev-py2.7.egg\IPython\utils\tests\test_process.py",line 90, in test_arg_split_win32
    nt.assert_equal(arg_split(argstr), argv)
  File "C:\python\ipydevel\VENV\py27\lib\site-packages\ipython-0.13.dev-py2.7.egg\IPython\utils\_process_win32.py", line 181, in arg_split
    result = [arg for arg in result_array_type.from_address(result_pointer)]
TypeError: integer expected
```



Discussion:

Resolving patch:
diff --git a/IPython/utils/_process_win32.py b/IPython/utils/_process_win32.py
--- a/IPython/utils/_process_win32.py
+++ b/IPython/utils/_process_win32.py
@@ -156,7 +156,7 @@ def getoutput(cmd):
 try:
     CommandLineToArgvW = ctypes.windll.shell32.CommandLineToArgvW
     CommandLineToArgvW.arg_types = [LPCWSTR, POINTER(c_int)]
-    CommandLineToArgvW.res_types = [POINTER(LPCWSTR)]
+    CommandLineToArgvW.restype = POINTER(LPCWSTR)
     LocalFree = ctypes.windll.kernel32.LocalFree
     LocalFree.res_type = HLOCAL
     LocalFree.arg_types = [HLOCAL]
@@ -178,7 +178,7 @@ def arg_split(commandline, posix=False, strict=True):
         argvn = c_int()
         result_pointer = CommandLineToArgvW(py3compat.cast_unicode(commandline.lstrip()), ctypes.byref(argvn))
         result_array_type = LPCWSTR * argvn.value
-        result = [arg for arg in result_array_type.from_address(result_pointer)]
+        result = [arg for arg in result_array_type.from_address(ctypes.addressof(result_pointer.contents))]
         retval = LocalFree(result_pointer)
         return result
 except AttributeError:


Test patch:
Repository: ipython/ipython

Issue:
Define sys.ps{1,2}
See https://bugs.launchpad.net/ipython/+bug/512826 for prior history.

Summary: we should define sys.ps{1,2} to make it easier for scripts to detect if they are being loaded interactively or not, and without ipython-specific checks.



Discussion:
I'm not sure that setting `sys.ps1` will make it easier for scripts to detect if they are being loaded interactively.  For example, consider

```
$ cat tst.py
import sys
try: print "sys.ps1=%r" % sys.ps1
except: print "no sys.ps1"

$ python -i tst.py
no sys.ps1
>>>
```

I think the author of the original issue might be better off passing some command line flags and parsing `sys.argv`.

Nonetheless it is true that `execfile('tst.py')` behaves differently

```
$ python
...
>>> execfile('tst.py')
sys.ps1='>>> '
```

and it'd be easy to set `sys.ps1` in `InteractiveShell.init_prompts` or similar.

Did you mean to open a PR for this?

Well, I'm not sure how I feel about it, so I haven't yet... but I will now, just to get some other commentary on the issue.


Resolving patch:
diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py
--- a/IPython/core/interactiveshell.py
+++ b/IPython/core/interactiveshell.py
@@ -637,6 +637,11 @@ def init_io(self):
     def init_prompts(self):
         self.prompt_manager = PromptManager(shell=self, config=self.config)
         self.configurables.append(self.prompt_manager)
+        # Set system prompts, so that scripts can decide if they are running
+        # interactively.
+        sys.ps1 = 'In : '
+        sys.ps2 = '...: '
+        sys.ps3 = 'Out: '
 
     def init_display_formatter(self):
         self.display_formatter = DisplayFormatter(config=self.config)


Test patch:
Repository: ipython/ipython

Issue:
scatter/gather fail with targets='all'
``` python
dview = rc.direct_view(targets='all')
dview.scatter('x', range(16))
```

gives:

```
TypeError: 'a' not valid str target, must be 'all'
```

Because it is trying to scatter across targets `['a', 'l', 'l']`.

Fix coming...



Discussion:

Resolving patch:
diff --git a/IPython/parallel/client/view.py b/IPython/parallel/client/view.py
--- a/IPython/parallel/client/view.py
+++ b/IPython/parallel/client/view.py
@@ -692,6 +692,9 @@ def scatter(self, key, seq, dist='b', flatten=False, targets=None, block=None, t
         block = block if block is not None else self.block
         track = track if track is not None else self.track
         targets = targets if targets is not None else self.targets
+        
+        # construct integer ID list:
+        targets = self.client._build_targets(targets)[1]
 
         mapObject = Map.dists[dist]()
         nparts = len(targets)
@@ -730,6 +733,9 @@ def gather(self, key, dist='b', targets=None, block=None):
         mapObject = Map.dists[dist]()
         msg_ids = []
 
+        # construct integer ID list:
+        targets = self.client._build_targets(targets)[1]
+        
         for index, engineid in enumerate(targets):
             msg_ids.extend(self.pull(key, block=False, targets=engineid).msg_ids)
 


Test patch:
diff --git a/IPython/parallel/tests/test_view.py b/IPython/parallel/tests/test_view.py
--- a/IPython/parallel/tests/test_view.py
+++ b/IPython/parallel/tests/test_view.py
@@ -233,6 +233,15 @@ def test_scatter_gather_numpy(self):
         view.scatter('a', a)
         b = view.gather('a', block=True)
         assert_array_equal(b, a)
+    
+    def test_scatter_gather_lazy(self):
+        """scatter/gather with targets='all'"""
+        view = self.client.direct_view(targets='all')
+        x = range(64)
+        view.scatter('x', x)
+        gathered = view.gather('x', block=True)
+        self.assertEquals(gathered, x)
+        
 
     @dec.known_failure_py3
     @skip_without('numpy')
Repository: ipython/ipython

Issue:
Drag target very small if IPython Dashboard has no notebooks
When importing a notebook into the dashboard, the table of existing notebooks is the drag target. This is quite a small area. If the drag target is missed, the browser merely loads the ipynb file as plain text. Consider making the drag target larger, especially if the existing notebook list is empty.

Drag target very small if IPython Dashboard has no notebooks
When importing a notebook into the dashboard, the table of existing notebooks is the drag target. This is quite a small area. If the drag target is missed, the browser merely loads the ipynb file as plain text. Consider making the drag target larger, especially if the existing notebook list is empty.



Discussion:

Resolving patch:
diff --git a/IPython/frontend/html/notebook/handlers.py b/IPython/frontend/html/notebook/handlers.py
--- a/IPython/frontend/html/notebook/handlers.py
+++ b/IPython/frontend/html/notebook/handlers.py
@@ -590,7 +590,10 @@ class NotebookRootHandler(AuthenticatedHandler):
     @authenticate_unless_readonly
     def get(self):
         nbm = self.application.notebook_manager
+        km = self.application.kernel_manager
         files = nbm.list_notebooks()
+        for f in files :
+            f['kernel_id'] = km.kernel_for_notebook(f['notebook_id'])
         self.finish(jsonapi.dumps(files))
 
     @web.authenticated


Test patch:
Repository: ipython/ipython

Issue:
cython_magic uses importlib, which doesn't ship with py2.6
Sorry, I don't have time to fix this right now, but wanted to leave a report.

`importlib` was not in the standard library for python2.6, though [it has been backported](http://pypi.python.org/pypi/importlib/1.0.1).

Trying to run `%load_ext cythonmagic` results in this traceback:

```
/ipython/IPython/extensions/cythonmagic.py in <module>()
     18 import io
     19 import os, sys
---> 20 from importlib import import_module
     21 import imp
     22 

ImportError: No module named importlib
```

not sure if we should make people install it themselves, or if it's better to just put a copy in `IPython.external`



Discussion:
I'm -1 on adding something else to externals just for 2.6. We're trying to reduce the number of external libraries we bundle. I think it's fine to say that importlib is a dependency for that extension on Python 2.6.


Resolving patch:
diff --git a/IPython/extensions/cythonmagic.py b/IPython/extensions/cythonmagic.py
--- a/IPython/extensions/cythonmagic.py
+++ b/IPython/extensions/cythonmagic.py
@@ -17,7 +17,6 @@
 
 import io
 import os, sys
-from importlib import import_module
 import imp
 
 try:
@@ -101,7 +100,8 @@ def f(x):
             module = self._reloads[module_name]
             reload(module)
         else:
-            module = import_module(module_name)
+            __import__(module_name)
+            module = sys.modules[module_name]
             self._reloads[module_name] = module
         self._import_all(module)
 


Test patch:
Repository: ipython/ipython

Issue:
pyreadline version dependency not correctly checked
Installing IPython on windows with `python setup.py install` and pyreadline 1.5:

<pre>
C:\code\dev_trees\ipython [main-master]> ipython
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 0.13.dev -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
Traceback (most recent call last):
  File "C:\Python26\Scripts\ipython-script.py", line 9, in <module>
    load_entry_point('ipython==0.13.dev', 'console_scripts', 'ipython')()
  File "C:\Python26\lib\site-packages\ipython-0.13.dev-py2.6.egg\IPython\frontend\terminal\ipapp.py", line 409, in launch_new_instance
    app.start()
  File "C:\Python26\lib\site-packages\ipython-0.13.dev-py2.6.egg\IPython\frontend\terminal\ipapp.py", line 383, in start
    self.shell.mainloop()
  File "C:\Python26\lib\site-packages\ipython-0.13.dev-py2.6.egg\IPython\frontend\terminal\interactiveshell.py", line 290, in mainloop
    self.interact(display_banner=display_banner)
  File "C:\Python26\lib\site-packages\ipython-0.13.dev-py2.6.egg\IPython\frontend\terminal\interactiveshell.py", line 346, in interact
    hlen_b4_cell = self.readline.get_current_history_length()
AttributeError: 'module' object has no attribute 'get_current_history_length'
</pre>


I see that `setup.py` `requires` pyreadline >= 1.7.1, iff `setupext.check_for_readline()` returns False.  However, in my case, it returns True because the function does not check the version, and I have version 1.5.   I wasn't sure how best to put the version dependency into the function.



Discussion:

Resolving patch:
diff --git a/setupext/setupext.py b/setupext/setupext.py
--- a/setupext/setupext.py
+++ b/setupext/setupext.py
@@ -161,17 +161,22 @@ def check_for_pyzmq():
             return True
 
 def check_for_readline():
+    from distutils.version import LooseVersion
     try:
         import readline
     except ImportError:
         try:
             import pyreadline
-        except ImportError:
+            vs = pyreadline.release.version
+        except (ImportError, AttributeError):
             print_status('readline', "no (required for good interactive behavior)")
             return False
-        else:
-            print_status('readline', "yes pyreadline-"+pyreadline.release.version)
+        if LooseVersion(vs).version >= [1,7,1]:
+            print_status('readline', "yes pyreadline-" + vs)
             return True
+        else:
+            print_status('readline', "no pyreadline-%s < 1.7.1" % vs)
+            return False
     else:
         print_status('readline', "yes")
         return True


Test patch:
Repository: ipython/ipython

Issue:
script magics cause terminal spam
since the addition of script magics in cdde5bba8 one gets a _which_ error message outputted to the terminal on each start:
e.g. if no python3 is available:

```
$ ipython
which: no python3 in (/scratch/jtaylor/progs/localinst/lib/ccache:/scratch/jtaylor/progs/localinst/bin:/scratch/jtaylor/progs/Reflex/software/bin:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/jtaylor/gasgano/bin:/scisoft/bin:/home/jtaylor/scripts:/scratch/jtaylor/progs/root/bin)
```



Discussion:

Resolving patch:
diff --git a/IPython/utils/_process_posix.py b/IPython/utils/_process_posix.py
--- a/IPython/utils/_process_posix.py
+++ b/IPython/utils/_process_posix.py
@@ -36,7 +36,7 @@ def _find_cmd(cmd):
     """Find the full path to a command using which."""
 
     path = sp.Popen(['/usr/bin/env', 'which', cmd],
-                    stdout=sp.PIPE).communicate()[0]
+                    stdout=sp.PIPE, stderr=sp.PIPE).communicate()[0]
     return py3compat.bytes_to_str(path)
 
 


Test patch:
Repository: ipython/ipython

Issue:
Shutdown qtconsole problem?
The following from the windows console, after starting, then stopping a qtconsole session with cntrl-D, 

C:\Users\burnett>ipython qtconsole --pylab
[IPKernelApp] To connect another client to this kernel, use:
[IPKernelApp] --existing kernel-5140.json
Traceback (most recent call last):
  File "c:\python27\lib\site-packages\IPython\frontend\qt\console\mainwindow.py", line 853, in update_restart_checkbox
    self.confirm_restart_kernel_action.setChecked(widget.confirm_restart)
AttributeError: 'NoneType' object has no attribute 'confirm_restart'



Discussion:

Resolving patch:
diff --git a/IPython/frontend/qt/console/mainwindow.py b/IPython/frontend/qt/console/mainwindow.py
--- a/IPython/frontend/qt/console/mainwindow.py
+++ b/IPython/frontend/qt/console/mainwindow.py
@@ -849,6 +849,8 @@ def toggle_confirm_restart_active_frontend(self):
         self.confirm_restart_kernel_action.setChecked(widget.confirm_restart)
 
     def update_restart_checkbox(self):
+        if self.active_frontend is None:
+            return
         widget = self.active_frontend
         self.confirm_restart_kernel_action.setChecked(widget.confirm_restart)
 


Test patch:
Repository: ipython/ipython

Issue:
%page not working
```
    %page
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-336-e5a187ccb094> in <module>()
    ----> 1 get_ipython().magic(u'page')

    c:\python26\lib\site-packages\ipython-0.13.dev-py2.6.egg\IPython\core\interactiveshell.pyc in magic(self, arg_s)
       2150         magic_name, _, magic_arg_s = arg_s.partition(' ')
       2151         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
    -> 2152         return self.run_line_magic(magic_name, magic_arg_s)
       2153 
       2154     #-------------------------------------------------------------------------

    c:\python26\lib\site-packages\ipython-0.13.dev-py2.6.egg\IPython\core\interactiveshell.pyc in run_line_magic(self, magic_name, line)
       2076                 args.append(sys._getframe(stack_depth).f_locals)
       2077             with self.builtin_trap:
    -> 2078                 result = fn(*args)
       2079             return result
       2080 

    c:\python26\lib\site-packages\ipython-0.13.dev-py2.6.egg\IPython\core\magics\basic.pyc in page(self, parameter_s)

    c:\python26\lib\site-packages\ipython-0.13.dev-py2.6.egg\IPython\core\magic.pyc in <lambda>(f, *a, **k)
        188     # but it's overkill for just that one bit of state.
        189     def magic_deco(arg):
    --> 190         call = lambda f, *a, **k: f(*a, **k)
        191 
        192         if callable(arg):

    c:\python26\lib\site-packages\ipython-0.13.dev-py2.6.egg\IPython\core\magics\basic.pyc in page(self, parameter_s)
        186 
        187         oname = args and args or '_'
    --> 188         info = self._ofind(oname)
        189         if info['found']:
        190             txt = (raw and str or pformat)( info['obj'] )

    AttributeError: 'BasicMagics' object has no attribute '_ofind'
```



Discussion:
It probably needs to be `self.shell._ofind` - do you want to make a pull request?

Sure. That fixes it. I just tried it.

Thanks!

On Thursday, June 14, 2012 8:32:27 AM, Thomas Kluyver wrote:

> It probably needs to be `self.shell._ofind` - do you want to make a pull request?
> 
> ---
> 
> Reply to this email directly or view it on GitHub:
> https://github.com/ipython/ipython/issues/1960#issuecomment-6332055


Resolving patch:
diff --git a/IPython/core/magics/basic.py b/IPython/core/magics/basic.py
--- a/IPython/core/magics/basic.py
+++ b/IPython/core/magics/basic.py
@@ -185,7 +185,7 @@ def page(self, parameter_s=''):
         raw = 'r' in opts
 
         oname = args and args or '_'
-        info = self._ofind(oname)
+        info = self.shell._ofind(oname)
         if info['found']:
             txt = (raw and str or pformat)( info['obj'] )
             page.page(txt)


Test patch:
Repository: ipython/ipython

Issue:
Notebook server can't start cluster with hyphen-containing profile name
Notebook server can't start cluster of the profile which name contains non-alphabetical and non-numeric characters such as `-`.  This is because of the regex defined in `notebookapp._profile_regex`:

```
_profile_regex = r"(?P<profile>[a-zA-Z0-9]+)"
```

See: [notebookapp._profile_regex](https://github.com/ipython/ipython/blob/e96a12794e378c6c8fa40c7addc6ba90e9a9f67a/IPython/frontend/html/notebook/notebookapp.py#L78)

Probably this regex should allow anything other than slashes?  At least I think it's better to add `_` and `-`.



Discussion:

Resolving patch:
diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py
--- a/IPython/frontend/html/notebook/notebookapp.py
+++ b/IPython/frontend/html/notebook/notebookapp.py
@@ -75,7 +75,7 @@
 _kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)"
 _kernel_action_regex = r"(?P<action>restart|interrupt)"
 _notebook_id_regex = r"(?P<notebook_id>\w+-\w+-\w+-\w+-\w+)"
-_profile_regex = r"(?P<profile>[a-zA-Z0-9]+)"
+_profile_regex = r"(?P<profile>[^\/]+)" # there is almost no text that is invalid
 _cluster_action_regex = r"(?P<action>start|stop)"
 
 


Test patch:
Repository: ipython/ipython

Issue:
handle too old wx
the wx gui integration does not seem to work with wx 2.6 see this bug:
https://bugs.launchpad.net/bugs/998716

the version should be checked and error should be displayed, currently it spams the terminal with exceptions



Discussion:

Resolving patch:
diff --git a/IPython/lib/inputhook.py b/IPython/lib/inputhook.py
--- a/IPython/lib/inputhook.py
+++ b/IPython/lib/inputhook.py
@@ -20,6 +20,7 @@
     ctypes = None
 import os
 import sys
+from distutils.version import LooseVersion as V
 
 from IPython.utils.warn import warn
 
@@ -200,6 +201,13 @@ def enable_wx(self, app=None):
             import wx
             app = wx.App(redirect=False, clearSigInt=False)
         """
+        import wx
+        
+        wx_version = V(wx.__version__).version
+        
+        if wx_version < [2, 8]:
+            raise ValueError("requires wxPython >= 2.8, but you have %s" % wx.__version__)
+        
         from IPython.lib.inputhookwx import inputhook_wx
         self.set_inputhook(inputhook_wx)
         self._current_gui = GUI_WX


Test patch:
Repository: ipython/ipython

Issue:
except-shadows-builtin osm.py:687
except ValueError, IOError:

should be

except (ValueError, IOError):



Discussion:

Resolving patch:
diff --git a/IPython/core/magics/osm.py b/IPython/core/magics/osm.py
--- a/IPython/core/magics/osm.py
+++ b/IPython/core/magics/osm.py
@@ -684,7 +684,7 @@ def pycat(self, parameter_s=''):
 
         try :
             cont = self.shell.find_user_code(parameter_s)
-        except ValueError, IOError:
+        except (ValueError, IOError):
             print "Error: no such file, variable, URL, history range or macro"
             return
 


Test patch:
Repository: ipython/ipython

Issue:
Unable to use print_stats after %prun -r in notebook
This applies to the notebook, I haven't tried this in plain ipython or the console: If I get a `pstats.Stats` object using `%prun -r` nothing shows up when I call `print_stats`. However, if I save to a file using `%prun -D` and then load the file using `pstats.Stats` calling `print_stats` works perfectly.

I'm using a fresh install of IPython 0.13.



Discussion:
It seems that `%prun` changes the `stream` attribute to redirect output into a `StringIO` buffer.

```
In [25]: p = %prun -r print("hello")
hello
         2 function calls in 0.000 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 <string>:1(<module>)
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}


In [26]: p.print_stats()
Out[26]: <pstats.Stats instance at 0x3aa25a8>

In [27]: p.stream = sys.stdout

In [28]: p.print_stats()
         2 function calls in 0.000 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 <string>:1(<module>)
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}


Out[28]: <pstats.Stats instance at 0x3aa25a8>
```


Resolving patch:
diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py
--- a/IPython/core/magics/execution.py
+++ b/IPython/core/magics/execution.py
@@ -226,20 +226,12 @@ def prun(self, parameter_s='', cell=None, user_mode=True,
 
         # Trap output.
         stdout_trap = StringIO()
-
-        if hasattr(stats,'stream'):
-            # In newer versions of python, the stats object has a 'stream'
-            # attribute to write into.
+        stats_stream = stats.stream
+        try:
             stats.stream = stdout_trap
             stats.print_stats(*lims)
-        else:
-            # For older versions, we manually redirect stdout during printing
-            sys_stdout = sys.stdout
-            try:
-                sys.stdout = stdout_trap
-                stats.print_stats(*lims)
-            finally:
-                sys.stdout = sys_stdout
+        finally:
+            stats.stream = stats_stream
 
         output = stdout_trap.getvalue()
         output = output.rstrip()


Test patch: