Repository: ipython/ipython

Issue:
ExecutionResult uses __qualname__, breaks PY2
Sage uses `run_cell()` a lot to test the desired command line behavior. But with IPython 5 I get:

```
IPython 5.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]: ip = get_ipython()

In [2]: ip.run_cell('1+1')
Out[2]: 2
Out[2]: ---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/home/vbraun/Sage/git-develop/local/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
    668                 type_pprinters=self.type_printers,
    669                 deferred_pprinters=self.deferred_printers)
--> 670             printer.pretty(obj)
    671             printer.flush()
    672             return stream.getvalue()

/home/vbraun/Sage/git-develop/local/lib/python2.7/site-packages/IPython/lib/pretty.pyc in pretty(self, obj)
    381                             if callable(meth):
    382                                 return meth(obj, self, cycle)
--> 383             return _default_pprint(obj, self, cycle)
    384         finally:
    385             self.end_group()

/home/vbraun/Sage/git-develop/local/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _default_pprint(obj, p, cycle)
    501     if _safe_getattr(klass, '__repr__', None) not in _baseclass_reprs:
    502         # A user-provided repr. Find newlines and replace them with p.break_()
--> 503         _repr_pprint(obj, p, cycle)
    504         return
    505     p.begin_group(1, '<')

/home/vbraun/Sage/git-develop/local/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _repr_pprint(obj, p, cycle)
    692     """A pprint that just redirects to the normal repr function."""
    693     # Find newlines and replace them with p.break_()
--> 694     output = repr(obj)
    695     for idx,output_line in enumerate(output.splitlines()):
    696         if idx:

/home/vbraun/Sage/git-develop/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in __repr__(self)
    185     def __repr__(self):
    186         return '<%s object at %x, execution_count=%s error_before_exec=%s error_in_exec=%s result=%s>' %\
--> 187                 (self.__class__.__qualname__, id(self), self.execution_count, self.error_before_exec, self.error_in_exec, repr(self.result))
    188 
    189 

AttributeError: type object 'ExecutionResult' has no attribute '__qualname__'
```



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
@@ -187,8 +187,12 @@ def raise_error(self):
             raise self.error_in_exec
 
     def __repr__(self):
+        if sys.version_info > (3,):
+            name = self.__class__.__qualname__
+        else:
+            name = self.__class__.__name__
         return '<%s object at %x, execution_count=%s error_before_exec=%s error_in_exec=%s result=%s>' %\
-                (self.__class__.__qualname__, id(self), self.execution_count, self.error_before_exec, self.error_in_exec, repr(self.result))
+                (name, id(self), self.execution_count, self.error_before_exec, self.error_in_exec, repr(self.result))
 
 
 class InteractiveShell(SingletonConfigurable):


Test patch: