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

Issue:
Bug in pretty printing
The code in `IPython.lib.pretty.RepresentationPrinter.pretty` has a bug: it fails to look in the class `__dict__`s of the classes in the MRO. Fixes this is pretty easy:

```
--- pretty.py.orig  2012-07-11 15:38:34.000000000 +0200
+++ pretty.py   2012-07-11 15:32:05.000000000 +0200
@@ -354,7 +354,7 @@
                         # Some objects automatically create any requested
                         # attribute. Try to ignore most of them by checking for
                         # callability.
-                        if '_repr_pretty_' in obj_class.__dict__:
+                        if '_repr_pretty_' in cls.__dict__:
                             meth = obj_class._repr_pretty_
                             if isinstance(meth, collections.Callable):
                                 return meth(obj, self, cycle)
```



Discussion:

Resolving patch:
diff --git a/IPython/lib/pretty.py b/IPython/lib/pretty.py
--- a/IPython/lib/pretty.py
+++ b/IPython/lib/pretty.py
@@ -353,8 +353,8 @@ def pretty(self, obj):
                         # Some objects automatically create any requested
                         # attribute. Try to ignore most of them by checking for
                         # callability.
-                        if '_repr_pretty_' in obj_class.__dict__:
-                            meth = obj_class._repr_pretty_
+                        if '_repr_pretty_' in cls.__dict__:
+                            meth = cls._repr_pretty_
                             if callable(meth):
                                 return meth(obj, self, cycle)
             return _default_pprint(obj, self, cycle)


Test patch:
diff --git a/IPython/lib/tests/test_pretty.py b/IPython/lib/tests/test_pretty.py
--- a/IPython/lib/tests/test_pretty.py
+++ b/IPython/lib/tests/test_pretty.py
@@ -45,6 +45,14 @@ def _repr_pretty_(self, p, cycle):
         p.text("MyDict(...)")
 
 
+class Dummy1(object):
+    def _repr_pretty_(self, p, cycle):
+        p.text("Dummy1(...)")
+
+class Dummy2(Dummy1):
+    _repr_pretty_ = None
+
+
 def test_indentation():
     """Test correct indentation in groups"""
     count = 40
@@ -63,3 +71,14 @@ def test_dispatch():
     expectedoutput = "MyDict(...)"
 
     nt.assert_equals(gotoutput, expectedoutput)
+
+
+def test_callability_checking():
+    """
+    Test that the _repr_pretty_ method is tested for callability and skipped if
+    not.
+    """
+    gotoutput = pretty.pretty(Dummy2())
+    expectedoutput = "Dummy1(...)"
+
+    nt.assert_equals(gotoutput, expectedoutput)
Repository: ipython/ipython

Issue:
[qtconsole] Namespace not empty at startup
in qtconsole, namespace already contain `IPython.core.usage` as usage , instead of beeing empty.



Discussion:
Wow that was neat... just hijacked your issue into my pull request...

Did you did it with hub ? 
I thought it was only possible with your own issues !

what append if usage has already been imported before (if it is possible to import it before)

Yes, what if `usage` has been previously imported.  We could `import ... as _usage` ?  

I'm just wondering wether or not we will have some other magics that would need to be register by the frontend and how if we need an easier mechanisme for that.

for the time beeing, importting usage as _usage, deletig it after is fine with me.
we can even wrap in a 

``` python
try : 
    _usage
except NameError:
    from IPython.core import usage as _usage
    get_ipython().register_magic_function(usage.page_guiref, 'line', 'guiref')
    del _usage
```


Resolving patch:
diff --git a/IPython/frontend/qt/console/ipython_widget.py b/IPython/frontend/qt/console/ipython_widget.py
--- a/IPython/frontend/qt/console/ipython_widget.py
+++ b/IPython/frontend/qt/console/ipython_widget.py
@@ -272,8 +272,12 @@ def _started_kernel(self):
     def _load_guiref_magic(self):
         """Load %guiref magic."""
         self.kernel_manager.shell_channel.execute('\n'.join([
-            "from IPython.core import usage",
-            "get_ipython().register_magic_function(usage.page_guiref, 'line', 'guiref')",
+            "try:",
+            "    _usage",
+            "except:",
+            "    from IPython.core import usage as _usage",
+            "    get_ipython().register_magic_function(_usage.page_guiref, 'line', 'guiref')",
+            "    del _usage",
         ]), silent=True)
         
     #---------------------------------------------------------------------------


Test patch:
Repository: ipython/ipython

Issue:
Tab completion does not work with IPython.embed_kernel()
When I pause a script with IPython.embed_kernel() and connect to the kernel with qtconsole, whil %whos show all the objects correctly, tab completion does not work. 

Specifically, tab completion for any names generated by original script does not work, and also, it does not work for new objects generated in the qtconsole either.  



Discussion:

Resolving patch:
diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py
--- a/IPython/core/interactiveshell.py
+++ b/IPython/core/interactiveshell.py
@@ -1809,7 +1809,6 @@ def init_readline(self):
             self.readline_no_record = no_op_context
             self.set_readline_completer = no_op
             self.set_custom_completer = no_op
-            self.set_completer_frame = no_op
             if self.readline_use:
                 warn('Readline services not available or not loaded.')
         else:
diff --git a/IPython/zmq/ipkernel.py b/IPython/zmq/ipkernel.py
--- a/IPython/zmq/ipkernel.py
+++ b/IPython/zmq/ipkernel.py
@@ -908,6 +908,7 @@ def embed_kernel(module=None, local_ns=None, **kwargs):
     
     app.kernel.user_module = module
     app.kernel.user_ns = local_ns
+    app.shell.set_completer_frame()
     app.start()
 
 def main():


Test patch:
Repository: ipython/ipython

Issue:
oct2py v >= 0.3.1 doesn't need h5py anymore
The octave magic docs/examples should update this  information.



Discussion:

Resolving patch:
diff --git a/IPython/extensions/octavemagic.py b/IPython/extensions/octavemagic.py
--- a/IPython/extensions/octavemagic.py
+++ b/IPython/extensions/octavemagic.py
@@ -8,8 +8,8 @@
 
 .. note::
 
-  The ``oct2py`` module needs to be installed separately, and in turn depends
-  on ``h5py``.  Both can be obtained using ``easy_install`` or ``pip``.
+  The ``oct2py`` module needs to be installed separately and
+  can be obtained using ``easy_install`` or ``pip``.
 
 Usage
 =====


Test patch:
Repository: ipython/ipython

Issue:
Can't trigger startup code in Engines
Newly launched ipcluster instances don't execute code from the variable c.IPEngineApp.startup_command .  Min suggested that this is from the new forked Kernel implementation, which doesn't share the startup config.

More context: http://mail.scipy.org/pipermail/ipython-user/2012-July/010769.html



Discussion:

Resolving patch:
diff --git a/IPython/parallel/apps/ipengineapp.py b/IPython/parallel/apps/ipengineapp.py
--- a/IPython/parallel/apps/ipengineapp.py
+++ b/IPython/parallel/apps/ipengineapp.py
@@ -316,15 +316,22 @@ def init_engine(self):
         
         
         try:
-            exec_lines = config.Kernel.exec_lines
+            exec_lines = config.IPKernelApp.exec_lines
         except AttributeError:
-            config.Kernel.exec_lines = []
-            exec_lines = config.Kernel.exec_lines
+            try:
+                exec_lines = config.InteractiveShellApp.exec_lines
+            except AttributeError:
+                exec_lines = config.IPKernelApp.exec_lines = []
+        try:
+            exec_files = config.IPKernelApp.exec_files
+        except AttributeError:
+            try:
+                exec_files = config.InteractiveShellApp.exec_files
+            except AttributeError:
+                exec_files = config.IPKernelApp.exec_files = []
         
         if self.startup_script:
-            enc = sys.getfilesystemencoding() or 'utf8'
-            cmd="execfile(%r)" % self.startup_script.encode(enc)
-            exec_lines.append(cmd)
+            exec_files.append(self.startup_script)
         if self.startup_command:
             exec_lines.append(self.startup_command)
 
diff --git a/IPython/parallel/engine/engine.py b/IPython/parallel/engine/engine.py
--- a/IPython/parallel/engine/engine.py
+++ b/IPython/parallel/engine/engine.py
@@ -34,7 +34,7 @@
 from IPython.parallel.util import disambiguate_url
 
 from IPython.zmq.session import Message
-from IPython.zmq.ipkernel import Kernel
+from IPython.zmq.ipkernel import Kernel, IPKernelApp
 
 class EngineFactory(RegistrationFactory):
     """IPython engine"""
@@ -198,10 +198,15 @@ def url(key):
             self.kernel = Kernel(config=self.config, int_id=self.id, ident=self.ident, session=self.session,
                     control_stream=control_stream, shell_streams=shell_streams, iopub_socket=iopub_socket,
                     loop=loop, user_ns=self.user_ns, log=self.log)
+            
             self.kernel.shell.display_pub.topic = cast_bytes('engine.%i.displaypub' % self.id)
+            
+            # FIXME: This is a hack until IPKernelApp and IPEngineApp can be fully merged
+            app = IPKernelApp(config=self.config, shell=self.kernel.shell, kernel=self.kernel, log=self.log)
+            app.init_profile_dir()
+            app.init_code()
+            
             self.kernel.start()
-
-
         else:
             self.log.fatal("Registration Failed: %s"%msg)
             raise Exception("Registration Failed: %s"%msg)


Test patch:
Repository: ipython/ipython

Issue:
Change NewNotebook handler to use 30x redirect
rewriting [the url for new notebooks](https://github.com/ipython/ipython/blob/master/IPython/frontend/html/notebook/static/js/savewidget.js#L127) seem to cause problem with jQuery tabs (#2206).

I propose to change the NewNotebook handler to send a redirect 302 with the  URL of the new notebook.



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
@@ -123,6 +123,14 @@ def auth_f(self, *args, **kwargs):
     else:
         return auth_f(self, *args, **kwargs)
 
+def urljoin(*pieces):
+    """Join componenet of url into a relative url
+
+    Use to prevent double slash when joining subpath
+    """
+    striped = [s.strip('/') for s in pieces]
+    return '/'.join(s for s in striped if s)
+
 #-----------------------------------------------------------------------------
 # Top-level handlers
 #-----------------------------------------------------------------------------
@@ -267,17 +275,7 @@ def get(self):
         nbm = self.application.notebook_manager
         project = nbm.notebook_dir
         notebook_id = nbm.new_notebook()
-        self.render(
-            'notebook.html', project=project,
-            notebook_id=notebook_id,
-            base_project_url=self.application.ipython_app.base_project_url,
-            base_kernel_url=self.application.ipython_app.base_kernel_url,
-            kill_kernel=False,
-            read_only=False,
-            logged_in=self.logged_in,
-            login_available=self.login_available,
-            mathjax_url=self.application.ipython_app.mathjax_url,
-        )
+        self.redirect('/'+urljoin(self.application.ipython_app.base_project_url, notebook_id))
 
 
 class NamedNotebookHandler(AuthenticatedHandler):
@@ -663,17 +661,7 @@ def get(self, notebook_id):
         nbm = self.application.notebook_manager
         project = nbm.notebook_dir
         notebook_id = nbm.copy_notebook(notebook_id)
-        self.render(
-            'notebook.html', project=project,
-            notebook_id=notebook_id,
-            base_project_url=self.application.ipython_app.base_project_url,
-            base_kernel_url=self.application.ipython_app.base_kernel_url,
-            kill_kernel=False,
-            read_only=False,
-            logged_in=self.logged_in,
-            login_available=self.login_available,
-            mathjax_url=self.application.ipython_app.mathjax_url,
-        )
+        self.redirect('/'+urljoin(self.application.ipython_app.base_project_url, notebook_id))
 
 
 #-----------------------------------------------------------------------------


Test patch:
Repository: ipython/ipython

Issue:
Regression in .embed()
As reported by @certik in the IPython-dev mailing list:

Before this commit:

```
b70ac127e2c3698ea643b15af7d6bb5783ff3e7e is the first bad commit
commit b70ac127e2c3698ea643b15af7d6bb5783ff3e7e
Author: Bradley M. Froehle <brad.froehle@gmail.com>
Date:   Wed Jul 4 15:02:21 2012 -0700

    embed(): Default to the future compile flags of the calling frame.
```

This is how things used to work in Qsnake (http://qsnake.com/):

```
$ qsnake
----------------------------------------------------------------------
| Qsnake Version 0.9.12, Release Date: May 7, 2011                   |
| Type lab() for the GUI.                                            |
----------------------------------------------------------------------

In [1]: 4 / 3.
Out[1]: 1.3333333333333333
```

After that commit, this is how it works now:

```
$ qsnake
----------------------------------------------------------------------
| Qsnake Version 0.9.12, Release Date: May 7, 2011                   |
| Type lab() for the GUI.                                            |
----------------------------------------------------------------------

In [1]: 4 / 3.
TypeError: unsupported operand type(s) for |: 'NoneType' and 'int'
```

Here is how I call .embed():

```
    banner = "..."
    namespace = {"lab": run_lab}
    c = IPython.config.loader.Config()
    c.InteractiveShell.confirm_exit = False
    IPython.frontend.terminal.embed.InteractiveShellEmbed(config=c,
            user_ns=namespace, banner1=banner).mainloop(local_ns={})
```

Would anyone know what the problem is?



Discussion:
In some experimentation, the `TypeError` appears regardless of the command entered.

I've got a patch, pull request coming soon.


Resolving patch:
diff --git a/IPython/frontend/terminal/embed.py b/IPython/frontend/terminal/embed.py
--- a/IPython/frontend/terminal/embed.py
+++ b/IPython/frontend/terminal/embed.py
@@ -200,7 +200,8 @@ class DummyMod(object):
             module.__dict__ = global_ns
 
         # Get locals and globals from caller
-        if (local_ns is None or module is None) and self.default_user_namespaces:
+        if ((local_ns is None or module is None or compile_flags is None)
+            and self.default_user_namespaces):
             call_frame = sys._getframe(stack_depth).f_back
 
             if local_ns is None:
@@ -233,7 +234,8 @@ class DummyMod(object):
             self.init_user_ns()
 
         # Compiler flags
-        self.compile.flags = compile_flags
+        if compile_flags is not None:
+            self.compile.flags = compile_flags
 
         # Patch for global embedding to make sure that things don't overwrite
         # user globals accidentally. Thanks to Richard <rxe@renre-europe.com>


Test patch:
Repository: ipython/ipython

Issue:
SSH passwordless check with OpenSSH checks for the wrong thing
The pattern passed to pexpect is '[Ppassword]:', which looks for any of those letters followed by ':', and not, as the intention seems to be, for 'Password:'.  The correct pattern is '[Pp]assword:'.

This is at IPython/external/ssh/tunnel.py:100.



Discussion:
I agree. Do you want to open a pull request?


Resolving patch:
diff --git a/IPython/external/ssh/tunnel.py b/IPython/external/ssh/tunnel.py
--- a/IPython/external/ssh/tunnel.py
+++ b/IPython/external/ssh/tunnel.py
@@ -97,7 +97,7 @@ def _try_passwordless_openssh(server, keyfile):
     p = pexpect.spawn(cmd)
     while True:
         try:
-            p.expect('[Ppassword]:', timeout=.1)
+            p.expect('[Pp]assword:', timeout=.1)
         except pexpect.TIMEOUT:
             continue
         except pexpect.EOF:


Test patch:
Repository: ipython/ipython

Issue:
client doesn't use connection file's 'location' in disambiguating 'interface'
be9601be0603cd5de781c4f91b8fc6a3120c9839 seems to have changed client.py to stop using `location` in the call to `util.disambiguate_ip_address` (previously `util.disambiguate_url`).  This means that if `interface`'s address is '*', the client tries to connect to localhost, which doesn't seem to me to be the correct behaviour.

The fix appears to be as simple as

```
-        addr = util.disambiguate_ip_address(addr)
+        addr = util.disambiguate_ip_address(addr, location)
```



Discussion:
Indeed - I caught the same typo in ipengineapp, but missed this one.  Want to make a Pull Request?


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
@@ -418,7 +418,7 @@ def __init__(self, url_file=None, profile=None, profile_dir=None, ipython_dir=No
         location = cfg.setdefault('location', None)
         
         proto,addr = cfg['interface'].split('://')
-        addr = util.disambiguate_ip_address(addr)
+        addr = util.disambiguate_ip_address(addr, location)
         cfg['interface'] = "%s://%s" % (proto, addr)
         
         # turn interface,port into full urls:


Test patch:
Repository: ipython/ipython

Issue:
print name for IPython Notebooks has become uninformative
In versions prior to 0.13, the web page containing a print view would have the notebook name as the title.  This meant that when printing the notebook to a PDF printer, the resulting PDF file would have the name of the notebook as the file name. 

In version 0.13, the print view has the name "Notebook" regardless of the name of the worksheet. 

This is very inconvenient, and I don't see any reason for the change.  Could you please change back to using the worksheet name for the title of the print view?



Discussion:
hum... I don't see what could have trigged that.
We will investigate.

as a workaround, you can execute this: 

```
window.document.title = "IPython Notebook : "+IPython.notebook.get_notebook_name() 
```

In the javascript console of your browser.

Thanks.  I have about two hundred notebooks (just counted :-) for lectures right now, though, so the issue isn't one of getting the title up there (I can also do that with PDF), it's really one of being able to print notebooks without too much hassle when I need the.  (Maybe I can do something with a JavaScript injection add-on to automate this on at least one machine.)

to generate pdf in batch, just use 
http://github.com/ipython/nbconvert

if you are on 0.14 dev, 
you can overrite any js file by putting it into `your/profile/dir/static/js/same_name_as_source.js` 
cp/past the one from the source and tweek it as you wish.


Resolving patch:
diff --git a/IPython/frontend/html/notebook/nbmanager.py b/IPython/frontend/html/notebook/nbmanager.py
--- a/IPython/frontend/html/notebook/nbmanager.py
+++ b/IPython/frontend/html/notebook/nbmanager.py
@@ -117,7 +117,7 @@ def get_notebook(self, notebook_id, format=u'json'):
             # should match the Python in-memory format.
             kwargs['split_lines'] = False
         data = current.writes(nb, format, **kwargs)
-        name = nb.get('name','notebook')
+        name = nb.metadata.get('name','notebook')
         return last_modified, name, data
 
     def read_notebook_object(self, notebook_id):


Test patch:
Repository: ipython/ipython

Issue:
HTML lists seem to interfere with the QtConsole display
Hi all,

We are trying to use the awesome QtConsole with some custom HTML output of our objects.

Some of these objects contains HTML lists. But when we display them the following happens.

![](http://i.imgur.com/emFVL.png)

Hopefully this is just an error in the way we are using the console, display objects, or HTML So we'd love to be corrected if that is the case. :)

Thanks!



Discussion:
I can definitely confirm this.  FWIW, saving the notebook as HTML produces [this](https://raw.github.com/gist/3383276/0c9a21f6730c94f531b345d9bd4393284875b815/ipython.html).  Stripping all of the style attributes gives a [more readable](https://raw.github.com/gist/3383276/046efeaefda90e44d1ff929658477a309b10ece3/ipython-stripped.html) file.

Based on this, my working hypothesis is that we essentially are inserting the html, moving to the "end" (which is not actually after the list is over but instead after the word 'item') then inserting a newline and finally the next prompt.

For example, note that `HTML('<ul><li>item</li></ul><p>bah!</p>')` does display properly.


Resolving patch:
diff --git a/IPython/frontend/qt/console/console_widget.py b/IPython/frontend/qt/console/console_widget.py
--- a/IPython/frontend/qt/console/console_widget.py
+++ b/IPython/frontend/qt/console/console_widget.py
@@ -858,6 +858,11 @@ def _append_custom(self, insert, input, before_prompt=False):
 
         return result
 
+    def _append_block(self, block_format=None, before_prompt=False):
+        """ Appends an new QTextBlock to the end of the console buffer.
+        """
+        self._append_custom(self._insert_block, block_format, before_prompt)
+
     def _append_html(self, html, before_prompt=False):
         """ Appends HTML at the end of the console buffer.
         """
@@ -1545,6 +1550,13 @@ def _insert_continuation_prompt(self, cursor):
             self._continuation_prompt = self._insert_html_fetching_plain_text(
                 cursor, self._continuation_prompt_html)
 
+    def _insert_block(self, cursor, block_format=None):
+        """ Inserts an empty QTextBlock using the specified cursor.
+        """
+        if block_format is None:
+            block_format = QtGui.QTextBlockFormat()
+        cursor.insertBlock(block_format)
+
     def _insert_html(self, cursor, html):
         """ Inserts HTML using the specified cursor in such a way that future
             formatting is unaffected.
@@ -1866,7 +1878,7 @@ def _show_prompt(self, prompt=None, html=False, newline=True):
             cursor.movePosition(QtGui.QTextCursor.Left,
                                 QtGui.QTextCursor.KeepAnchor)
             if cursor.selection().toPlainText() != '\n':
-                self._append_plain_text('\n')
+                self._append_block()
 
         # Write the prompt.
         self._append_plain_text(self._prompt_sep)


Test patch:
Repository: ipython/ipython

Issue:
interactiveshell.py misses urllib and io_open imports
cf15c8f0ed4493492b50e8fccb72175157afac7c seems to have accidentally removed them.

used in line 2957 and 2973

also affects 0.13.1 branch



Discussion:

Resolving patch:
diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py
--- a/IPython/core/interactiveshell.py
+++ b/IPython/core/interactiveshell.py
@@ -29,17 +29,11 @@
 import sys
 import tempfile
 import types
-
-# We need to use nested to support python 2.6, once we move to >=2.7, we can
-# use the with keyword's new builtin support for nested managers
-try:
-    from contextlib import nested
-except:
-    from IPython.utils.nested_context import nested
+import urllib
+from io import open as io_open
 
 from IPython.config.configurable import SingletonConfigurable
 from IPython.core import debugger, oinspect
-from IPython.core import history as ipcorehist
 from IPython.core import magic
 from IPython.core import page
 from IPython.core import prefilter


Test patch: