Suppress beg tbs from `collapse_eg()`

It was originally this way; I forgot to flip it back when discarding the
`except*` handler impl..

Specially handle the `exc.__cause__` case where we raise from any
detected underlying cause and OW `from None` to suppress the eg's tb.
to_asyncio_eoc_signal
Tyler Goodlet 2025-07-25 20:05:51 -04:00
parent 26526b86c3
commit fc77e6eca5
1 changed files with 12 additions and 35 deletions

View File

@ -97,11 +97,11 @@ def get_collapsed_eg(
async def collapse_eg( async def collapse_eg(
hide_tb: bool = True, hide_tb: bool = True,
# XXX, for ex. will always show begs containing single taskc
ignore: set[Type[BaseException]] = { ignore: set[Type[BaseException]] = {
# trio.Cancelled, # trio.Cancelled,
}, },
add_notes: bool = True, add_notes: bool = True,
bp: bool = False,
): ):
''' '''
If `BaseExceptionGroup` raised in the body scope is If `BaseExceptionGroup` raised in the body scope is
@ -115,30 +115,6 @@ async def collapse_eg(
yield yield
except BaseExceptionGroup as _beg: except BaseExceptionGroup as _beg:
beg = _beg beg = _beg
# TODO, remove this rant..
#
# except* BaseException as beg:
# ^XXX WOW.. good job cpython. ^
# like, never ever EVER use this!! XD
#
# turns out rasing from an `except*`-block has the opposite
# behaviour of normal `except` and further can *never* be used to
# get the equiv of,
# `trio.open_nursery(strict_exception_groups=False)`
#
# ------ docs ------
# https://docs.python.org/3/reference/compound_stmts.html#except-star
#
# > Any remaining exceptions that were not handled by any
# > except* clause are re-raised at the end, along with all
# > exceptions that were raised from within the except*
# > clauses. If this list contains more than one exception to
# > reraise, they are combined into an exception group.
if bp:
from tractor.devx import pause
await pause(shield=True)
if ( if (
(exc := get_collapsed_eg(beg)) (exc := get_collapsed_eg(beg))
and and
@ -158,16 +134,17 @@ async def collapse_eg(
): ):
exc.add_note(from_group_note) exc.add_note(from_group_note)
raise exc # raise exc
# ^^ this will leave the orig beg tb above with the
# ?TODO? not needed right? # "during the handling of <beg> the following.."
# if cause := exc.__cause__: # So, instead do..
# raise exc# from cause #
# else: if cause := exc.__cause__:
# # raise exc from beg raise exc from cause
# # suppress "during handling of <the beg>" else:
# # output in tb/console. # suppress "during handling of <the beg>"
# raise exc from None # output in tb/console.
raise exc from None
# keep original # keep original
raise # beg raise # beg