Add some tooling params to `collapse_eg()`

moar_eg_smoothing
Tyler Goodlet 2025-06-13 22:06:55 -04:00
parent 00583b7671
commit 6c46882545
1 changed files with 7 additions and 2 deletions

View File

@ -44,7 +44,10 @@ def maybe_collapse_eg(
@acm @acm
async def collapse_eg(): async def collapse_eg(
hide_tb: bool = True,
raise_from_src: bool = False,
):
''' '''
If `BaseExceptionGroup` raised in the body scope is If `BaseExceptionGroup` raised in the body scope is
"collapse-able" (in the same way that "collapse-able" (in the same way that
@ -52,13 +55,15 @@ async def collapse_eg():
only raise the lone emedded non-eg in in place. only raise the lone emedded non-eg in in place.
''' '''
__tracebackhide__: bool = hide_tb
try: try:
yield yield
except* BaseException as beg: except* BaseException as beg:
if ( if (
exc := maybe_collapse_eg(beg) exc := maybe_collapse_eg(beg)
) is not beg: ) is not beg:
raise exc from_exc = beg if raise_from_src else None
raise exc from from_exc
raise beg raise beg