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

Issue:
Output for semicolon-terminated lines with comments
cf https://github.com/JuliaLang/IJulia.jl/issues/109

The output of a semicolon-terminated line with comment is not suppressed in IPython.

```
b = 1
b; # foo
```

give `Out[13]: 1`

```
b = 1
b;
```

does not.

Havent found such and issue on our tracker.

 @takluyver you are the best with the input machinery and coroutines; Thoughts ?

(Because of the comment @stevengj in sus-cited issue, marking as prio-high, but won't  mind if priority decreased later, or not fixed)



Discussion:
the comma-end detection is probably just `rstrip().endswith(';')` rather than tokenizing. If anything, the comments over there point to the priority being low, not high.


Resolving patch:
diff --git a/IPython/core/displayhook.py b/IPython/core/displayhook.py
--- a/IPython/core/displayhook.py
+++ b/IPython/core/displayhook.py
@@ -26,6 +26,7 @@
 import sys
 
 from IPython.core.formatters import _safe_get_formatter_method
+from IPython.core import inputsplitter
 from IPython.config.configurable import Configurable
 from IPython.utils import io
 from IPython.utils.py3compat import builtin_mod
@@ -100,12 +101,10 @@ def quiet(self):
         # do not print output if input ends in ';'
         try:
             cell = self.shell.history_manager.input_hist_parsed[self.prompt_count]
-            if cell.rstrip().endswith(';'):
-                return True
+            return inputsplitter.remove_comments(cell).rstrip().endswith(';')
         except IndexError:
             # some uses of ipshellembed may fail here
-            pass
-        return False
+            return False
 
     def start_displayhook(self):
         """Start the displayhook, initializing resources."""


Test patch:
diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py
--- a/IPython/core/tests/test_interactiveshell.py
+++ b/IPython/core/tests/test_interactiveshell.py
@@ -98,13 +98,17 @@ def test_multiline_string_cells(self):
     def test_dont_cache_with_semicolon(self):
         "Ending a line with semicolon should not cache the returned object (GH-307)"
         oldlen = len(ip.user_ns['Out'])
-        a = ip.run_cell('1;', store_history=True)
-        newlen = len(ip.user_ns['Out'])
-        self.assertEqual(oldlen, newlen)
+        for cell in ['1;', '1; #a', '1;1;']:
+            ip.run_cell(cell, store_history=True)
+            newlen = len(ip.user_ns['Out'])
+            self.assertEqual(oldlen, newlen)
+        i = 0
         #also test the default caching behavior
-        ip.run_cell('1', store_history=True)
-        newlen = len(ip.user_ns['Out'])
-        self.assertEqual(oldlen+1, newlen)
+        for cell in ['1', '1 #;', '1;1']:
+            ip.run_cell(cell, store_history=True)
+            newlen = len(ip.user_ns['Out'])
+            i += 1
+            self.assertEqual(oldlen+i, newlen)
 
     def test_In_variable(self):
         "Verify that In variable grows with user input (GH-284)"
Repository: ipython/ipython

Issue:
Converting notebooks with spaces in their names to RST gives broken images
I am using `ipython nbconvert --to rst example1.ipynb` to convert my example notebooks into reStructuredText, for incorporation into my package's Sphinx documentation. This works quite well, unless the filename has a space in it. In this case, any image files from my notebooks are lost when I run Sphinx's `make html`. 

My guess is that the problem seems is in the generated rst file, where the `.. image` command may need to be escaped or quoted somehow to work with spaces in the filename.

I note that a similar issue was reported and resolved for latex output in issue #3774, however the solution was specific to latex.



Discussion:

Resolving patch:
diff --git a/IPython/nbconvert/filters/markdown.py b/IPython/nbconvert/filters/markdown.py
--- a/IPython/nbconvert/filters/markdown.py
+++ b/IPython/nbconvert/filters/markdown.py
@@ -103,7 +103,7 @@ def markdown2html_marked(source, encoding='utf-8'):
     return out.rstrip('\n')
 
 def markdown2rst(source):
-    """Convert a markdown string to LaTeX via pandoc.
+    """Convert a markdown string to ReST via pandoc.
 
     This function will raise an error if pandoc is not installed.
     Any error messages generated by pandoc are printed to stderr.


Test patch:
Repository: ipython/ipython

Issue:
scp checking for existence of directories: directory names are incorrect
Commit d02d22204f9445ad3634b150ac5dc8a360b05c95 is supposed to ensure that SSHlaunchers check that destination directories exist when copying files between hosts (see issue #3411). However there is a bug where the hostname (or ip address) of the destination machine is included in the directory name by mistake.

The offending code is:

``` python
check_output(self.ssh_cmd + self.ssh_args + \
    [self.location, 'mkdir', '-p', '--', remote_dir]
)
```

The problem is that `remote_dir` includes the hostname (or ip) of the destination machine, so for example a directory that should be created on the destination machine at:

```
~/.ipython/profile_ssh/security
```

will instead be created at:

```
~/<DESTINATION HOSTNAME>/.ipython/profile_ssh/security
```



Discussion:

Resolving patch:
diff --git a/IPython/parallel/apps/launcher.py b/IPython/parallel/apps/launcher.py
--- a/IPython/parallel/apps/launcher.py
+++ b/IPython/parallel/apps/launcher.py
@@ -593,7 +593,7 @@ def find_args(self):
     
     def _send_file(self, local, remote):
         """send a single file"""
-        remote = "%s:%s" % (self.location, remote)
+        full_remote = "%s:%s" % (self.location, remote)
         for i in range(10):
             if not os.path.exists(local):
                 self.log.debug("waiting for %s" % local)
@@ -605,8 +605,8 @@ def _send_file(self, local, remote):
         check_output(self.ssh_cmd + self.ssh_args + \
             [self.location, 'mkdir', '-p', '--', remote_dir]
         )
-        self.log.info("sending %s to %s", local, remote)
-        check_output(self.scp_cmd + [local, remote])
+        self.log.info("sending %s to %s", local, full_remote)
+        check_output(self.scp_cmd + [local, full_remote])
     
     def send_files(self):
         """send our files (called before start)"""


Test patch:
Repository: ipython/ipython

Issue:
Update COPYING.txt
[From the dev meeting, March 20, 2014](https://hackpad.com/2014-IPython-Weekly-Development-Meetings-v8bNV6EmqVd#:h=March-20,-2014)

We should use this header or something similar for source files:

``` python
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
```



Discussion:
Related question:  If we use a copyright string like the one mentioned above, should we still use the horizontal breaks made of dashes to separate code regions, i.e.

``` python
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
```

I think that kind of formatting is completely optional. These days I find
myself writing shorter files and not dividing code using banners like that,
but occasionally, it is nice to add formatting to code to help readability.
I don't think any action is needed on this front.

On Tue, Mar 25, 2014 at 11:11 AM, Jonathan Frederic <
notifications@github.com> wrote:

> Related question: If we use a copyright string like the one mentioned
> above, should we still use the horizontal breaks made of dashes to separate
> code regions, i.e.
> 
> #-----------------------------------------------------------------------------# Classes#-----------------------------------------------------------------------------
> 
> ## 
> 
> Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/issues/5425#issuecomment-38600298
> .

## 

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

> I don't think any action is needed on this front.

But the date & names in COPYING.txt should still be updated, right?

Yes

On Tue, Mar 25, 2014 at 11:22 AM, Jonathan Frederic <
notifications@github.com> wrote:

> I don't think any action is needed on this front.
> 
> But the date & names in COPYING.txt should still be updated, right?
> 
> ## 
> 
> Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/issues/5425#issuecomment-38601673
> .

## 

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@
 #
 #  Distributed under the terms of the Modified BSD License.
 #
-#  The full license is in the file COPYING.txt, distributed with this software.
+#  The full license is in the file COPYING.rst, distributed with this software.
 #-----------------------------------------------------------------------------
 
 #-----------------------------------------------------------------------------


Test patch:
Repository: ipython/ipython

Issue:
FormatterWarning for SVG matplotlib output in notebook
Running Python 3.3 and from the current git, I'm having problems getting the inline matplotlib machinery to render SVG image files. I have made up a gist that shows the problem [1]. This is from an empty profile. Note that the default output works fine, but then using the instructions here [2] to get SVG output, the plot does not render and the FormatterWarning is thrown. It looks like a Python 3 compatibility thing, but it may bear noting that this is also on Windows.

[1] http://nbviewer.ipython.org/gist/flacjacket/9605481
[2] http://ipython.org/ipython-doc/dev/api/generated/IPython.core.magics.pylab.html



Discussion:
That does look like a Python 3 compatibility question. I've assigned it to myself to investigate more.

It's the type validation in formatters - SVG is assumed to be text, but it's being given as bytes. We can either
- allow bytes through by adding `_return_type = (bytes, unicode_type)` [here](https://github.com/ipython/ipython/blob/master/IPython/core/formatters.py#L724), and assume it is utf8 (I think this is what happens implicitly on Python 2.7), or 
- ensure that we produce text rather than bytes when generating inline SVG figures [here](https://github.com/ipython/ipython/blob/master/IPython/core/pylabtools.py#L98).

At least the first one fixes it for me. Just blindly wrapping the return on L128 in a `str()` call for the second breaks all plot output, I'm not sure at first glance how that would need to be implemented to test it.

It shouldn't be wrapped in str, it should explicitly call `decode`.


Resolving patch:
diff --git a/IPython/core/pylabtools.py b/IPython/core/pylabtools.py
--- a/IPython/core/pylabtools.py
+++ b/IPython/core/pylabtools.py
@@ -96,7 +96,10 @@ def figsize(sizex, sizey):
 
 
 def print_figure(fig, fmt='png', bbox_inches='tight', **kwargs):
-    """Print a figure to an image, and return the resulting bytes
+    """Print a figure to an image, and return the resulting file data
+    
+    Returned data will be bytes unless ``fmt='svg'``,
+    in which case it will be unicode.
     
     Any keyword args are passed to fig.canvas.print_figure,
     such as ``quality`` or ``bbox_inches``.
@@ -125,7 +128,10 @@ def print_figure(fig, fmt='png', bbox_inches='tight', **kwargs):
     
     bytes_io = BytesIO()
     fig.canvas.print_figure(bytes_io, **kw)
-    return bytes_io.getvalue()
+    data = bytes_io.getvalue()
+    if fmt == 'svg':
+        data = data.decode('utf-8')
+    return data
     
 def retina_figure(fig, **kwargs):
     """format a figure as a pixel-doubled (retina) PNG"""


Test patch:
diff --git a/IPython/core/tests/test_pylabtools.py b/IPython/core/tests/test_pylabtools.py
--- a/IPython/core/tests/test_pylabtools.py
+++ b/IPython/core/tests/test_pylabtools.py
@@ -58,7 +58,7 @@ def test_figure_to_svg():
     ax.plot([1,2,3])
     plt.draw()
     svg = pt.print_figure(fig, 'svg')[:100].lower()
-    nt.assert_in(b'doctype svg', svg)
+    nt.assert_in(u'doctype svg', svg)
 
 def _check_pil_jpeg_bytes():
     """Skip if PIL can't write JPEGs to BytesIO objects"""
Repository: ipython/ipython

Issue:
IPython.parallel.Client behavior as iterator
Iterating over a Client only works if the engine ids start at 0, resulting in inconsistent behavior:

```
In [1]: from IPython.parallel import Client

In [2]: c = Client()

In [3]: print c[:]
<DirectView [0, 1, 2, 3]>

In [4]: for ct in c:
   ...:     print ct
   ...:     
<DirectView 0>
<DirectView 1>
<DirectView 2>
<DirectView 3>

In [5]: c = Client()

In [6]: print c[:]
<DirectView [4, 5, 6, 7]>

In [7]: for ct in c:
   ...:     print ct
   ...:     

In [8]: 
```

Whether Client should be an iterator or not, I think it should at least be consistent.



Discussion:
I didn't intend for Client to be iterable (it's a side effect of defining `__getitem__`). Might as well make it consistent, since the behavior is already there.


Resolving patch:
diff --git a/IPython/parallel/client/client.py b/IPython/parallel/client/client.py
--- a/IPython/parallel/client/client.py
+++ b/IPython/parallel/client/client.py
@@ -921,7 +921,16 @@ def __getitem__(self, key):
             raise TypeError("key by int/slice/iterable of ints only, not %s"%(type(key)))
         else:
             return self.direct_view(key)
-
+    
+    def __iter__(self):
+        """Since we define getitem, Client is iterable
+        
+        but unless we also define __iter__, it won't work correctly unless engine IDs
+        start at zero and are continuous.
+        """
+        for eid in self.ids:
+            yield self.direct_view(eid)
+    
     #--------------------------------------------------------------------------
     # Begin public methods
     #--------------------------------------------------------------------------


Test patch:
diff --git a/IPython/parallel/tests/test_client.py b/IPython/parallel/tests/test_client.py
--- a/IPython/parallel/tests/test_client.py
+++ b/IPython/parallel/tests/test_client.py
@@ -41,6 +41,11 @@ def test_ids(self):
         self.add_engines(2)
         self.assertEqual(len(self.client.ids), n+2)
     
+    def test_iter(self):
+        self.minimum_engines(4)
+        engine_ids = [ view.targets for view in self.client ]
+        self.assertEqual(engine_ids, self.client.ids)
+    
     def test_view_indexing(self):
         """test index access for views"""
         self.minimum_engines(4)
Repository: ipython/ipython

Issue:
Kernel start fails when using --browser argument
repro steps: 
1. Start ipython notebook with browser flag: 
    - $ ipython notebook --browser firefox
    - Note that this successfully starts the notebook in firefox instead of the default browser
2. Open/create a notebook document
3. Wait for kernel to start

What I expect to see:
everything should just work :)

What I see:
A "Kernel restarting" dialog opens in the browser window for a little while, and finally switches to a "Dead kernel" dialog.

The console log shows evidence of attempting to restart the kernel, ending with the following:
[IPKernelApp] CRITICAL | Bad config encountered during initialization:
[IPKernelApp] CRITICAL | Unrecognized flag: '--browser'
2014-04-11 15:58:30.172 [NotebookApp] WARNING | KernelRestarter: restart failed
2014-04-11 15:58:30.174 [NotebookApp] WARNING | Kernel 218d6d1f-0779-42b8-802f-5b3df58bc919 died, removing from map.
ERROR:root:kernel 218d6d1f-0779-42b8-802f-5b3df58bc919 restarted failed!



Discussion:

Resolving patch:
diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py
--- a/IPython/html/notebookapp.py
+++ b/IPython/html/notebookapp.py
@@ -294,7 +294,7 @@ def start(self):
 aliases.pop('f', None)
 
 notebook_aliases = [u'port', u'port-retries', u'ip', u'keyfile', u'certfile',
-                    u'notebook-dir', u'profile', u'profile-dir']
+                    u'notebook-dir', u'profile', u'profile-dir', 'browser']
 
 #-----------------------------------------------------------------------------
 # NotebookApp


Test patch:
Repository: ipython/ipython

Issue:
can't require a function named `f`
It took me a while to figure this one out:

``` python
def f(x):
    return(x)

@require(f):
def g(y):
    return f(y)
```

gives:

```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-86-98a37b0c736a> in <module>()
----> 1 @require(f)
      2 def g(y):
      3     return f(y)
      4

/usr/local/lib/python2.7/dist-packages/IPython/parallel/controller/dependency.pyc in require(*objects, **mapping)
    133     for name, obj in mapping.items():
    134         mapping[name] = can(obj)
--> 135     return depend(_require, *names, **mapping)
    136
    137 class Dependency(set):

TypeError: __init__() got multiple values for keyword argument 'f'
```

I believe the cause is the use of `f` as a name in the constructor [here](https://github.com/ipython/ipython/blob/1934e25cb2fbaace740d97bc33ab45f01d1be962/IPython/parallel/controller/dependency.py#L43-L49).

This seems like a bit of an arbitrary restriction; it may not be possible to get around having to forbid the use of _some_ function name, but at least we could maybe use something less likely to collide with users' things (`_f` maybe?).



Discussion:
yeah, poor choice of argument names. I'll make it something less likely to collide.


Resolving patch:
diff --git a/IPython/parallel/controller/dependency.py b/IPython/parallel/controller/dependency.py
--- a/IPython/parallel/controller/dependency.py
+++ b/IPython/parallel/controller/dependency.py
@@ -40,8 +40,8 @@ def f(m,n,p)
     raises an UnmetDependency error, then the task will not be run
     and another engine will be tried.
     """
-    def __init__(self, f, *args, **kwargs):
-        self.f = f
+    def __init__(self, _wrapped_f, *args, **kwargs):
+        self.f = _wrapped_f
         self.args = args
         self.kwargs = kwargs
     
@@ -54,14 +54,14 @@ class dependent(object):
     in traditional decorators, which are not picklable.
     """
 
-    def __init__(self, f, df, *dargs, **dkwargs):
-        self.f = f
+    def __init__(self, _wrapped_f, _wrapped_df, *dargs, **dkwargs):
+        self.f = _wrapped_f
         name = getattr(f, '__name__', 'f')
         if py3compat.PY3:
             self.__name__ = name
         else:
             self.func_name = name
-        self.df = df
+        self.df = _wrapped_df
         self.dargs = dargs
         self.dkwargs = dkwargs
     


Test patch:
Repository: ipython/ipython

Issue:
Move ssh out of external and into lib
This module does not belong in external - it cannot be replaced by an external system module.



Discussion:
This is incorrect. IPython.external.ssh is a copy of upstream zmq.ssh.

That said, I don't think we've been sure to do backporting fixes properly, so we should probably do a few things:
1. rename to external.zmq_ssh to make it clearer where it comes from
2. also make this clear in a docstring in `zmq_ssh.__init__.py`
3. make sure there aren't any fixes in there that we failed to send upstream

We cannot make use of a system installed zmq.ssh instead of this, so we cannot unbundle this as is for Fedora.


Resolving patch:
diff --git a/IPython/external/ssh/__init__.py b/IPython/external/ssh/__init__.py
--- a/IPython/external/ssh/__init__.py
+++ b/IPython/external/ssh/__init__.py
@@ -0,0 +1,7 @@
+"""This is a copy of zmq.ssh"""
+
+try:
+    from zmq.ssh import *
+except ImportError:
+    from . import tunnel
+    from .tunnel import *


Test patch:
Repository: ipython/ipython

Issue:
inspect.findsource monkeypatch raises wrong exception for C extensions
In the following examples, `_yaml` is just a convenient way to specify a C extension that is already in the stdlib.

```
$ python -c 'import inspect, _yaml; print(inspect.findsource(_yaml))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.4/inspect.py", line 658, in findsource
    raise OSError('source code not available')
OSError: source code not available
$ python -c 'import inspect, IPython, _yaml; print(inspect.findsource(_yaml))'
<... traceback omitted ...>
SyntaxError: invalid or missing encoding declaration for '/usr/lib/python3.4/site-packages/_yaml.cpython-34m.so'
```

Why is this important?  There are now some packages (e.g. astropy) that unconditionally import IPython when they are themselves imported.  So, now, if I have my own package which imports astropy (or just IPython, in fact), and also contains some C extension (say `mypackage/foo.so`), then trying to run pydoc on another module in my package that uses the C extension (`pydoc mypackage.bar`, where `bar` imports `foo`) crashes with the uncaught SyntaxError, as (I guess) pydoc only catches an OSError but no SyntaxError when calling `findsource`.



Discussion:

Resolving patch:
diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py
--- a/IPython/core/ultratb.py
+++ b/IPython/core/ultratb.py
@@ -220,8 +220,17 @@ def findsource(object):
         return lines, lnum
     raise IOError('could not find code object')
 
-# Monkeypatch inspect to apply our bugfix.  This code only works with Python >= 2.5
-inspect.findsource = findsource
+# Monkeypatch inspect to apply our bugfix.
+def with_patch_inspect(f):
+    """decorator for monkeypatching inspect.findsource"""
+    def wrapped(*args, **kwargs):
+        save_findsource = inspect.findsource
+        inspect.findsource = findsource
+        try:
+            return f(*args, **kwargs)
+        finally:
+            inspect.findsource = save_findsource
+    return wrapped
 
 def fix_frame_records_filenames(records):
     """Try to fix the filenames in each record from inspect.getinnerframes().
@@ -243,6 +252,7 @@ def fix_frame_records_filenames(records):
     return fixed_records
 
 
+@with_patch_inspect
 def _fixed_getinnerframes(etb, context=1,tb_offset=0):
     LNUM_POS, LINES_POS, INDEX_POS =  2, 4, 5
 


Test patch: