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

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

danielballan added some commits Nov 25, 2018

ENH: Add a 'Minimal' xmode option.
This shows only the exception with no Traceback. If the Traceback is
needed, it can be retrieved using %tb.
ENH: Accept one-off exception mode setting for %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
```

@danielballan danielballan force-pushed the danielballan:xmode-minimal branch from 6b38657 to 188d043 Nov 26, 2018

@Carreau

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Contributor Author

commented Nov 27, 2018

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

This comment has been minimized.

Copy link
Member

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

4 checks passed

codecov/patch 34.61% of diff hit (target 0%)
Details
codecov/project 68.36% (-0.05%) compared to c3b288d
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@danielballan danielballan deleted the danielballan:xmode-minimal branch Nov 30, 2018

@danielballan

This comment has been minimized.

Copy link
Contributor Author

commented Nov 30, 2018

Thanks!

@Carreau

This comment has been minimized.

Copy link
Member

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
Projects
None yet
2 participants
You can’t perform that action at this time.