Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new exception-reporting mode and %tb mode option. #11509

Merged
merged 4 commits into from
Nov 29, 2018

Conversation

danielballan
Copy link
Contributor

@danielballan danielballan commented Nov 25, 2018

This adds a new mode to %xmode tentatively named 'Minimal' that shows only the exception --- no traceback.

In [1]: %xmode minimal                                                          
Exception reporting mode: Minimal                                               
                                                                                
In [2]: def f():                                                                
    ...:     3/0                                                                
    ...:                                                                        
                                                                                
In [3]: f()                                                                     
ZeroDivisionError: division by zero

In many contexts, you might say this leaves out too much information. Here is the context that I feel this will be useful in. Novice Python users are using IPython to execute rote procedures in a framework that happens to produce very deep tracebacks. They are completely lost in / overwhelmed by the full tracebacks and --- during the short time they grabble with IPython --- unable to absorb the rule, "Just scroll to the bottom." Therefore, an aggressively succinct %xmode setting may be less disorienting. Multiple experienced IPython users at my facility have suggested that this setting would be help elicit more useful bug reports.

Of course, if the problem is not immediately clear, it will be essential to access the full traceback. This could be done by switching to a more verbose %xmode and then using %tb to show the most recent traceback. In order to streamline that, this PR also adds an optional parameter to %tb that temporarily switches the exception-reporting mode for that single use.

In [4]: %tb verbose                                                             
---------------------------------------------------------------------------     
ZeroDivisionError                         Traceback (most recent call last)     
<ipython-input-3-c43e34e6d405> in <module>                                      
----> 1 f()                                                                     
        global f = <function f at 0x10e52de18>                                  
                                                                                
<ipython-input-2-cd4172d70b5b> in f()                                           
        1 def f():                                                               
----> 2     3/0                                                                 
        3                                                                       
                                                                                
ZeroDivisionError: division by zero                                             
                                                                                
In [5]: f()  # The default reporting mode has not been changed....              
ZeroDivisionError: division by zero

This shows only the exception with no Traceback. If the Traceback is
needed, it can be retrieved using %tb.
This makes it easy to access a more verbose representation that the
currently-active exception reporting mode provides.

```python
In [1]: %xmode minimal
Exception reporting mode: Minimal

In [2]: def f():
   ...:     3/0
   ...:

In [3]: f()
ZeroDivisionError: division by zero

In [4]: %tb verbose
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-3-c43e34e6d405> in <module>
----> 1 f()
        global f = <function f at 0x10e52de18>

<ipython-input-2-cd4172d70b5b> in f()
      1 def f():
----> 2     3/0
      3

ZeroDivisionError: division by zero

In [5]: f()  # The default reporting mode has not been changed....
ZeroDivisionError: division by zero
```
@Carreau
Copy link
Member

Carreau commented Nov 27, 2018

I'm +1 in principle. Will review when I have time.

I'll also love to have an "exception" mimebundle that could be handled by the frontend with collapsible section and stuff.

@danielballan
Copy link
Contributor Author

I like that minebundle idea a lot. I am a little bothered by how much this omits (though it might be good to have as an option). Something interactive that shows the first couple and last couple with an expandable middle would be ideal.

@Carreau Carreau added this to the 7.2 milestone Nov 29, 2018
@Carreau
Copy link
Member

Carreau commented Nov 29, 2018

+1. I'm going to try to get a release soon.

@Carreau Carreau merged commit 78441b6 into ipython:master Nov 29, 2018
@danielballan danielballan deleted the xmode-minimal branch November 30, 2018 03:52
@danielballan
Copy link
Contributor Author

Thanks!

@Carreau
Copy link
Member

Carreau commented Nov 30, 2018

(and 7.2 is out, currently writing announcements)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants