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

Issue:
pprint methods for collections use hard-wired class names
The pprint methods for collections classes (`_defaultdict_pprint`, _`ordereddict_pprint`, `_deque_pprint`, and `_counter_pprint`) have explicit class names in the function.  This gives inconsistent results when using subclasses of these classes.  For example `nltk.FreqDist` is a subclass of `collections.Counter`:

``` python
In [60]: pprint()
Pretty printing has been turned ON

In [61]: x = nltk.FreqDist(['a','b','a'])

In [62]: x
Out[62]: Counter({'a': 2, 'b': 1})

In [63]: pprint()
Pretty printing has been turned OFF

In [64]: x
Out[64]: FreqDist({'a': 2, 'b': 1})
```

I can't say I fully understand how the pretty printing dispatch works, but I think the fix is to replace this:

``` python
def _counter_pprint(obj, p, cycle):
    name = 'Counter'
    with p.group(len(name) + 1, name + '(', ')'):
        if cycle:
            p.text('...')
        elif len(obj):
            p.pretty(dict(obj))
```

with something like:

``` python
def _counter_pprint(obj, p, cycle):
    name = obj.__class__.__name__
    with p.group(len(name) + 1, name + '(', ')'):
        if cycle:
            p.text('...')
        elif len(obj):
            p.pretty(dict(obj))
```



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
@@ -791,7 +791,7 @@ def for_type_by_name(type_module, type_name, func):
 
 
 def _defaultdict_pprint(obj, p, cycle):
-    name = 'defaultdict'
+    name = obj.__class__.__name__
     with p.group(len(name) + 1, name + '(', ')'):
         if cycle:
             p.text('...')
@@ -802,7 +802,7 @@ def _defaultdict_pprint(obj, p, cycle):
             p.pretty(dict(obj))
 
 def _ordereddict_pprint(obj, p, cycle):
-    name = 'OrderedDict'
+    name = obj.__class__.__name__
     with p.group(len(name) + 1, name + '(', ')'):
         if cycle:
             p.text('...')
@@ -810,7 +810,7 @@ def _ordereddict_pprint(obj, p, cycle):
             p.pretty(list(obj.items()))
 
 def _deque_pprint(obj, p, cycle):
-    name = 'deque'
+    name = obj.__class__.__name__
     with p.group(len(name) + 1, name + '(', ')'):
         if cycle:
             p.text('...')
@@ -819,7 +819,7 @@ def _deque_pprint(obj, p, cycle):
 
 
 def _counter_pprint(obj, p, cycle):
-    name = 'Counter'
+    name = obj.__class__.__name__
     with p.group(len(name) + 1, name + '(', ')'):
         if cycle:
             p.text('...')


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
@@ -350,9 +350,12 @@ def test_collections_deque():
         nt.assert_equal(pretty.pretty(obj), expected)
 
 def test_collections_counter():
+    class MyCounter(Counter):
+        pass
     cases = [
         (Counter(), 'Counter()'),
         (Counter(a=1), "Counter({'a': 1})"),
+        (MyCounter(a=1), "MyCounter({'a': 1})"),
     ]
     for obj, expected in cases:
         nt.assert_equal(pretty.pretty(obj), expected)
Repository: ipython/ipython

Issue:
two characters system command are reduced to one in python3.4.3+ under debian unstable
After installing ipython as the following `pip3 install --user ipython`

I currently use fish shell as a shell so this is the following interaction

```
xcombelle@xcombelle-laptop ~> ipython3
Python 3.4.3+ (default, Oct 10 2015, 09:15:38) 
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- 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.

In [1]: !ls
fish: Unknown command 'l'
fish: l
      ^
```

the expected result would be the list of files and directory

I debug a little bit and think I found the culprit:
by commenting out [`FullEvalFormatter.v_eval definition`](https://github.com/ipython/ipython/blob/master/IPython/utils/text.py#L543) the problem disapear
I think the problem is related to [this python bug patch](https://hg.python.org/cpython/diff/9eae18e8af66/Lib/string.py) where the use and definition of `_vformat` changed



Discussion:

Resolving patch:
diff --git a/IPython/utils/text.py b/IPython/utils/text.py
--- a/IPython/utils/text.py
+++ b/IPython/utils/text.py
@@ -540,9 +540,7 @@ class FullEvalFormatter(Formatter):
     """
     # copied from Formatter._vformat with minor changes to allow eval
     # and replace the format_spec code with slicing
-    def _vformat(self, format_string, args, kwargs, used_args, recursion_depth):
-        if recursion_depth < 0:
-            raise ValueError('Max string recursion exceeded')
+    def vformat(self, format_string, args, kwargs):
         result = []
         for literal_text, field_name, format_spec, conversion in \
                 self.parse(format_string):


Test patch:
Repository: ipython/ipython

Issue:
display.Image should allow manual setting of format even when a local file is given
It appears that the `display.Image` class has some non-intuitive (and limiting) behavior for inferring the format of a locally-provided image.  I would have _thought_ that supplying the `format` keyword would allow me to override whatever format the IPython machinery decided the local file was in.  This is important for a use case where e.g. temporary files are used, as the file has _no_ extension, so you can't guess based on the filename.

However, if I do something like:
`IPython.display.Image(filename='/temp/somerandomfilename', format='jpg')`
to my surprise, it does _not_ try to interpret the file as a JPEG, but rather says `ValueError: Cannot embed the '/temp/somerandomfilename' image format`.

Is there a reason why this is the case, or could this be fixed?

(See also astropy/astropy-tutorials#97 for the context that this was encountered)



Discussion:

Resolving patch:
diff --git a/IPython/core/display.py b/IPython/core/display.py
--- a/IPython/core/display.py
+++ b/IPython/core/display.py
@@ -637,7 +637,7 @@ class Image(DisplayObject):
     _FMT_PNG = u'png'
     _ACCEPTABLE_EMBEDDINGS = [_FMT_JPEG, _FMT_PNG]
 
-    def __init__(self, data=None, url=None, filename=None, format=u'png',
+    def __init__(self, data=None, url=None, filename=None, format=None,
                  embed=None, width=None, height=None, retina=False,
                  unconfined=False, metadata=None):
         """Create a PNG/JPEG image object given raw data.
@@ -714,17 +714,27 @@ def __init__(self, data=None, url=None, filename=None, format=u'png',
         else:
             ext = None
 
-        if ext is not None:
-            format = ext.lower()
-            if ext == u'jpg' or ext == u'jpeg':
-                format = self._FMT_JPEG
-            if ext == u'png':
-                format = self._FMT_PNG
-        elif isinstance(data, bytes) and format == 'png':
-            # infer image type from image data header,
-            # only if format might not have been specified.
-            if data[:2] == _JPEG:
-                format = 'jpeg'
+        if format is None:
+            if ext is not None:
+                if ext == u'jpg' or ext == u'jpeg':
+                    format = self._FMT_JPEG
+                if ext == u'png':
+                    format = self._FMT_PNG
+                else:
+                    format = ext.lower()
+            elif isinstance(data, bytes):
+                # infer image type from image data header,
+                # only if format has not been specified.
+                if data[:2] == _JPEG:
+                    format = self._FMT_JPEG
+
+        if format.lower() == 'jpg':
+            # jpg->jpeg
+            format = self._FMT_JPEG
+
+        # failed to detect format, default png
+        if format is None:
+            format = 'png'
 
         self.format = unicode_type(format).lower()
         self.embed = embed if embed is not None else (url is None)


Test patch:
Repository: ipython/ipython

Issue:
Cannot inspect callable that raise in __bool__
The following should not raise.

``` python
class NoBoolCall:

    def __call__(self):
        pass
    def __bool__(self):
        raise NotImplementedError('Must be implemented')

b = NoBoolCall()
b?
```

Likely in `oinspect.py`:

```
835:       if callable_obj:
```

Should be `if callable_obj is not None`, though i'm not sure. 



Discussion:
`is not None` seems like the right change. How did you encounter this?

> How did you encounter this

Nothing you should [ever use in production](https://github.com/Carreau/undefined/blob/master/undefined/__init__.py#L11-L40), replacing a `sys.modules[somethings]` with a custom class with weird behavior. 


Resolving patch:
diff --git a/IPython/core/oinspect.py b/IPython/core/oinspect.py
--- a/IPython/core/oinspect.py
+++ b/IPython/core/oinspect.py
@@ -832,7 +832,7 @@ def info(self, obj, oname='', formatter=None, info=None, detail_level=0):
         else:
             callable_obj = None
 
-        if callable_obj:
+        if callable_obj is not None:
             try:
                 argspec = getargspec(callable_obj)
             except (TypeError, AttributeError):


Test patch:
diff --git a/IPython/core/tests/test_oinspect.py b/IPython/core/tests/test_oinspect.py
--- a/IPython/core/tests/test_oinspect.py
+++ b/IPython/core/tests/test_oinspect.py
@@ -172,6 +172,19 @@ class Awkward(object):
     def __getattr__(self, name):
         raise Exception(name)
 
+class NoBoolCall:
+    """
+    callable with `__bool__` raising should still be inspect-able.
+    """
+
+    def __call__(self):
+        """does nothing"""
+        pass
+
+    def __bool__(self):
+        """just raise NotImplemented"""
+        raise NotImplementedError('Must be implemented')
+
 
 def check_calltip(obj, name, call, docstring):
     """Generic check pattern all calltip tests will use"""
@@ -281,6 +294,9 @@ def test_info_awkward():
     # Just test that this doesn't throw an error.
     i = inspector.info(Awkward())
 
+def test_bool_raise():
+    inspector.info(NoBoolCall())
+
 def test_calldef_none():
     # We should ignore __call__ for all of these.
     for obj in [f, SimpleClass().method, any, str.upper]:
Repository: ipython/ipython

Issue:
Logging is not comprehensive with regard to %edit
Python 3.4.3, Python 4.0.0.

The IPython session copied to `ipython_session.py` in [this Gist](http://gist.github.com/horse-mans/b6691197932935b03fcf) produces the file `my_log.py`, also at that Gist. The first time `%edit` is run, the output line contains the complete contents of the file that was edited. If `%edit` is then called with a function argument, there is no output which contains the contents of the modifications.

If a person in a session is constantly making changes/tweaking a function definition with the `%edit` command, even the most verbose logging session will never capture these modifications, making it difficult to retrace one's steps if they rely on session logs.



Discussion:

Resolving patch:
diff --git a/IPython/core/magics/code.py b/IPython/core/magics/code.py
--- a/IPython/core/magics/code.py
+++ b/IPython/core/magics/code.py
@@ -147,6 +147,10 @@ def __init__(self, index):
 class CodeMagics(Magics):
     """Magics related to code management (loading, saving, editing, ...)."""
 
+    def __init__(self, *args, **kwargs):
+        self._knowntemps = set()
+        super(CodeMagics, self).__init__(*args, **kwargs)
+
     @line_magic
     def save(self, parameter_s=''):
         """Save a set of lines or a macro to a given filename.
@@ -661,6 +665,12 @@ def edit(self, parameter_s='',last_call=['','']):
             # just give up.
             return
 
+        if is_temp:
+            self._knowntemps.add(filename)
+        elif (filename in self._knowntemps):
+            is_temp = True
+
+
         # do actual editing here
         print('Editing...', end=' ')
         sys.stdout.flush()


Test patch:
Repository: ipython/ipython

Issue:
Cannot escape IPython.embed() when called repeatedly within function inside a for-loop
I am running `foo.py` from the command line, and it includes a function has a for loop, inside of which is a function that has an IPython.embed() statement. This is to initialize an interpreter at that point within the function to have access to those local variables. 

However, when trying to escape from the embedded interpreter, it only opens a new interpreter (presumably up to k times for the for loop), effectively locking that terminal.

It would be nice to have a command analogous to `ipdb`'s `q`, which immediately throws an exception and exits to the CLI in which `foo.py` was executed.



Discussion:

Resolving patch:
diff --git a/IPython/terminal/embed.py b/IPython/terminal/embed.py
--- a/IPython/terminal/embed.py
+++ b/IPython/terminal/embed.py
@@ -21,6 +21,7 @@
 from traitlets import Bool, CBool, Unicode
 from IPython.utils.io import ask_yes_no
 
+class KillEmbeded(Exception):pass
 
 # This is an additional magic that is exposed in embedded shells.
 @magics_class
@@ -46,12 +47,27 @@ def kill_embedded(self, parameter_s=''):
                    "once you exit.")
 
 
+    @line_magic
+    def exit_raise(self, parameter_s=''):
+        """%exit_raise Make the current embedded kernel exit and raise and exception.
+
+        This function sets an internal flag so that an embedded IPython will
+        raise a `IPython.terminal.embed.KillEmbeded` Exception on exit, and then exit the current I. This is
+        useful to permanently exit a loop that create IPython embed instance.
+        """
+
+        self.shell.should_raise = True
+        self.shell.ask_exit()
+
+
+
 class InteractiveShellEmbed(TerminalInteractiveShell):
 
     dummy_mode = Bool(False)
     exit_msg = Unicode('')
     embedded = CBool(True)
     embedded_active = CBool(True)
+    should_raise = CBool(False)
     # Like the base class display_banner is not configurable, but here it
     # is True by default.
     display_banner = CBool(True)
@@ -130,6 +146,10 @@ def __call__(self, header='', local_ns=None, module=None, dummy=None,
         if self.exit_msg is not None:
             print(self.exit_msg)
 
+        if self.should_raise:
+            raise KillEmbeded('Embedded IPython raising error, as user requested.')
+
+
     def mainloop(self, local_ns=None, module=None, stack_depth=0,
                  display_banner=None, global_ns=None, compile_flags=None):
         """Embeds IPython into a running python program.


Test patch:
Repository: ipython/ipython

Issue:
Cannot build ipython 4.0.3 with setuptools 18.2
I was just updating [a bunch of Python packages](https://github.com/NixOS/nixpkgs/pull/12552) for Nix, when I get the following error when building ipython 4.0.3:

```
error in ipython setup command: Invalid environment marker: sys_platform == "darwin" and platform_python_implementation == "CPython"
```

Now I'm not familiar with these markers but I can imagine it is related to the pip 8.0.2 update. 

The error occurs with all Python versions.



Discussion:
Hum, can you give us a bit more information at what point you get this error ? Like are you building a wheel ? installing ? Something else ?

We build wheels first using `python setup.py bdist_wheel`, and that's where this error occurs.
I just tested by using pip 7.1.2 again, and the problem still occured. The problem did not occur with ipython 4.0.0. I haven't tested (yet) with 4.0.1 or 4.0.2.

The problem began to occur in 4.0.1. Looking at the changes I think the culprit is https://github.com/ipython/ipython/commit/e2b269a4db1fc6313aef544a463c797e05a214d4

The building and installation was on an x86-64 linux machine.
setuptools 18.2

Hum that's likely a [setuptools issue](https://bitbucket.org/pypa/setuptools/issues/387/some-pep-426-environment-markers-are-not) which support `platform_python_implementation` only starting at `18.5`.

Thanks @Carreau 
Then this is an issue we have to solve at Nix I think. We've tried before to upgrade setuptools but it broke many packages. Now however, it seems we have to try either again, or start maintaining patches for those that require different versions.

Yeah, setuptools is the worst, but used everywhere.

Let me reopen, we can try to add a check for setuptools version in setup.py to make the failure more explicit.


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -172,6 +172,9 @@ def run(self):
 
 if len(needs_setuptools.intersection(sys.argv)) > 0:
     import setuptools
+    v = tuple(int(x) for x in setuptools.__version__.split('.'))
+    if v < (18,5):
+        raise ValueError('Setuptools version >=18.5 is required, found: %s'%setuptools.__version__)
 
 # This dict is used for passing extra arguments that are setuptools
 # specific to setup
@@ -191,6 +194,7 @@ def run(self):
     nbconvert = ['nbconvert'],
 )
 install_requires = [
+    'setuptools>=18.5'
     'decorator',
     'pickleshare',
     'simplegeneric>0.8',


Test patch:
Repository: ipython/ipython

Issue:
IPython.display.Image crash if passed invalid bytes
Used in notebook test suite for testing not tested in IPython.

```
Image("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94BCRQnOqNu0b4AAAAKSURBVAjXY2AAAAACAAHiIbwzAAAAAElFTkSuQmCC")
```

```
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-871bd9636d0c> in <module>()
----> 1 Image(b"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94BCRQnOqNu0b4AAAAKSURBVAjXY2AAAAACAAHiIbwzAAAAAElFTkSuQmCC".encode())

/Users/bussonniermatthias/anaconda3/lib/python3.5/site-packages/IPython/core/display.py in __init__(self, data, url, filename, format, embed, width, height, retina, unconfined, metadata)
    732                     format = self._FMT_JPEG
    733
--> 734         if format.lower() == 'jpg':
    735             # jpg->jpeg
    736             format = self._FMT_JPEG

AttributeError: 'NoneType' object has no attribute 'lower'
```

Probably a bad logic to detect the format if `data` is `bytes`, we likely also need a Python2 special case



Discussion:

Resolving patch:
diff --git a/IPython/core/display.py b/IPython/core/display.py
--- a/IPython/core/display.py
+++ b/IPython/core/display.py
@@ -12,7 +12,6 @@
 import struct
 import warnings
 
-from IPython.core.formatters import _safe_get_formatter_method
 from IPython.utils.py3compat import (string_types, cast_bytes_py2, cast_unicode,
                                      unicode_type)
 from IPython.testing.skipdoctest import skip_doctest
@@ -731,14 +730,14 @@ def __init__(self, data=None, url=None, filename=None, format=None,
                 if data[:2] == _JPEG:
                     format = self._FMT_JPEG
 
-        if format.lower() == 'jpg':
-            # jpg->jpeg
-            format = self._FMT_JPEG
-
         # failed to detect format, default png
         if format is None:
             format = 'png'
 
+        if format.lower() == 'jpg':
+            # jpg->jpeg
+            format = self._FMT_JPEG
+
         self.format = unicode_type(format).lower()
         self.embed = embed if embed is not None else (url is None)
 


Test patch:
diff --git a/IPython/core/tests/test_display.py b/IPython/core/tests/test_display.py
--- a/IPython/core/tests/test_display.py
+++ b/IPython/core/tests/test_display.py
@@ -43,6 +43,9 @@ def test_retina_jpeg():
     nt.assert_equal(md['width'], 1)
     nt.assert_equal(md['height'], 1)
 
+def test_base64image():
+    display.Image("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94BCRQnOqNu0b4AAAAKSURBVAjXY2AAAAACAAHiIbwzAAAAAElFTkSuQmCC")
+
 def test_image_filename_defaults():
     '''test format constraint, and validity of jpeg and png'''
     tpath = ipath.get_ipython_package_dir()
Repository: ipython/ipython

Issue:
tools/github_stats fails on 2fa. 
```
$ python tools/github_stats.py --milestone 4.1 --since-tag 4.0.0
no cache
fetching GitHub stats since 2015-08-12 00:00:00 (tag: 4.0.0, milestone: 4.1)
Please enter your github username and password. These are not stored, only used to get an oAuth token. You can revoke this at any time on Github.
Username: *****
Password:*****
Traceback (most recent call last):
  File "github_stats.py", line 165, in <module>
    auth=True)
  File "/Users/bussonniermatthias/dev/ipython/tools/gh_api.py", line 175, in get_milestone_id
    milestones = get_milestones(project, auth=auth, **params)
  File "/Users/bussonniermatthias/dev/ipython/tools/gh_api.py", line 168, in get_milestones
    headers = make_auth_header()
  File "/Users/bussonniermatthias/dev/ipython/tools/gh_api.py", line 73, in make_auth_header
    return {'Authorization': 'token ' + get_auth_token()}
  File "/Users/bussonniermatthias/dev/ipython/tools/gh_api.py", line 67, in get_auth_token
    response.raise_for_status()
  File "/Users/bussonniermatthias/anaconda3/lib/python3.5/site-packages/requests/models.py", line 840, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.github.com/authorizations
```



Discussion:
I will tackle this one in a couple of hours with @parleur.


Resolving patch:
diff --git a/tools/gh_api.py b/tools/gh_api.py
--- a/tools/gh_api.py
+++ b/tools/gh_api.py
@@ -64,6 +64,13 @@ def get_auth_token():
     }
     response = requests.post('https://api.github.com/authorizations',
                             auth=(user, pw), data=json.dumps(auth_request))
+    if response.status_code == 401 and response.headers.get('X-GitHub-OTP') == 'required; sms':
+        print("Your login API resquest a SMS one time password")
+        sms_pw = getpass.getpass("SMS password: ")
+        response = requests.post('https://api.github.com/authorizations',
+                            auth=(user, pw), 
+                            data=json.dumps(auth_request),
+                            headers={'X-GitHub-OTP':sms_pw})
     response.raise_for_status()
     token = json.loads(response.text)['token']
     keyring.set_password('github', fake_username, token)


Test patch: