-
-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restored the IPython custom error handler
Now it works with BaseExceptionGroup too.
- Loading branch information
Showing
12 changed files
with
241 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# This isn't really a package, everything in here is a standalone script. This | ||
# __init__.py is just to fool setup.py into actually installing the things. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# https://coverage.readthedocs.io/en/latest/subprocess.html | ||
try: | ||
import coverage | ||
except ImportError: # pragma: no cover | ||
pass | ||
else: | ||
coverage.process_startup() |
36 changes: 36 additions & 0 deletions
36
trio/_core/tests/test_multierror_scripts/ipython_custom_exc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import _common | ||
|
||
# Override the regular excepthook too -- it doesn't change anything either way | ||
# because ipython doesn't use it, but we want to make sure Trio doesn't warn | ||
# about it. | ||
import sys | ||
|
||
|
||
def custom_excepthook(*args): | ||
print("custom running!") | ||
return sys.__excepthook__(*args) | ||
|
||
|
||
sys.excepthook = custom_excepthook | ||
|
||
import IPython | ||
|
||
ip = IPython.get_ipython() | ||
|
||
|
||
# Set this to some random nonsense | ||
class SomeError(Exception): | ||
pass | ||
|
||
|
||
def custom_exc_hook(etype, value, tb, tb_offset=None): | ||
ip.showtraceback() | ||
|
||
|
||
ip.set_custom_exc((SomeError,), custom_exc_hook) | ||
|
||
import trio | ||
|
||
# The custom excepthook should run, because Trio was polite and didn't | ||
# override it | ||
raise trio.MultiError([ValueError(), KeyError()]) |
21 changes: 21 additions & 0 deletions
21
trio/_core/tests/test_multierror_scripts/simple_excepthook.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import _common | ||
|
||
import trio | ||
|
||
|
||
def exc1_fn(): | ||
try: | ||
raise ValueError | ||
except Exception as exc: | ||
return exc | ||
|
||
|
||
def exc2_fn(): | ||
try: | ||
raise KeyError | ||
except Exception as exc: | ||
return exc | ||
|
||
|
||
# This should be printed nicely, because Trio overrode sys.excepthook | ||
raise trio.MultiError([exc1_fn(), exc2_fn()]) |
7 changes: 7 additions & 0 deletions
7
trio/_core/tests/test_multierror_scripts/simple_excepthook_IPython.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import _common | ||
|
||
# To tickle the "is IPython loaded?" logic, make sure that Trio tolerates | ||
# IPython loaded but not actually in use | ||
import IPython | ||
|
||
import simple_excepthook |