ipywidgets
ipywidgets copied to clipboard
Do not suppress exceptions in Output widget context
Output widgets, when used as context managers in a with statement and in IPython, were suppressing exceptions (whose stacktrace would be printed to the output widget).
This change makes Output widgets not suppress an exception, which will make the control flow of the code transparent and same as if output widgets were not used.
For compatibility reasons, the previous behavior can be achieved by setting capture_exception attribute to True, in which case the context manager will suppress any exceptions thrown (if any).
Fixes #3208
TODO:
- Make decisions on the default behavior (see the unit tests) and potential breaking changes
- Update documentation
I am open to not changing the default behavior (see #3208) -- by the v8.0 release (#2750), although I think it is more reasonable to not suppress exceptions. Any opinions or feedbacks would be appreciated.
Interestingly, in JupyterLite it seems that an output widget does not capture exceptions, even though it does in ipykernel.
From @vidartf:
Making it backwards compatible by keeping the current default would also be a clear preference on my end.
I agree with Vidar. A very common case for output widgets is to capture output that would not otherwise be visible (like widget callbacks), and capturing and displaying exceptions is very valuable for seeing why callbacks did not work. Also, I think if there is a question, preserving backwards compatibility should have a high priority (there is a lot of widgets code out there that people don't want to change if they can help it)
@vidartf, any possibility this can be merged in 8.0? I can make requested changes quickly. It's kind of a breaking change, so I feel it would be included in the major version.
UPDATE: never mind, I missed that 8.0 has been already out. Looking forward to be merged in the next release. Should we also add warnings for changing default behaviors in future versions, say 9.x?