-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix tests for strict exception groups (#42)
* fix tests to work with strict and non-strict exception groups * add python 3.12 to build, drop python 3.7 (end of life) * upgrade dev dependencies where needed for newer python versions --------- Co-authored-by: John Belmonte <[email protected]>
- Loading branch information
1 parent
36bab0d
commit eeecd24
Showing
6 changed files
with
63 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Iterable | ||
from contextlib import contextmanager | ||
import sys | ||
|
||
if sys.version_info < (3, 11): | ||
from exceptiongroup import ExceptionGroup | ||
|
||
|
||
def _unroll_exceptions( | ||
exceptions: Iterable[Exception] | ||
) -> Iterable[Exception]: | ||
res: list[Exception] = [] | ||
for exc in exceptions: | ||
if isinstance(exc, ExceptionGroup): | ||
res.extend(_unroll_exceptions(exc.exceptions)) | ||
|
||
else: | ||
res.append(exc) | ||
return res | ||
|
||
|
||
@contextmanager | ||
def unwrap_exceptiongroups_single(): | ||
try: | ||
yield | ||
except ExceptionGroup as e: | ||
exceptions = _unroll_exceptions(e.exceptions) | ||
|
||
assert len(exceptions) == 1, "Exception group contains multiple exceptions" | ||
|
||
raise exceptions[0] |
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