From dc8562cf1430d558edda03b0700ab0380eef7bb3 Mon Sep 17 00:00:00 2001 From: goodboy Date: Thu, 25 Jun 2026 19:09:42 -0400 Subject: [PATCH] Adapt SIGINT test to `trio` strict exception-groups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `test_cancel_via_SIGINT_other_task` opened its nursery with the now-deprecated `strict_exception_groups=False`. Under strict EGs (trio's default since 0.25) the SIGINT-induced `KeyboardInterrupt` surfaces wrapped in a `BaseExceptionGroup` — alongside the child tasks' `Cancelled`s, so it's MULTI-exc and `collapse_eg()` can't fold it back to a bare KI (the `# why no work!?` the author hit). Drop the deprecated flag, use a default (strict) nursery, and assert the result is a bare `KeyboardInterrupt` OR a `BaseExceptionGroup` whose `.subgroup(KeyboardInterrupt)` is non-empty. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- tests/test_cancellation.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/test_cancellation.py b/tests/test_cancellation.py index c3644d88..ab26c03d 100644 --- a/tests/test_cancellation.py +++ b/tests/test_cancellation.py @@ -780,21 +780,28 @@ def test_cancel_via_SIGINT_other_task( async def main(): # should never timeout since SIGINT should cancel the current program with trio.fail_after(timeout): - async with ( - - # XXX ?TODO? why no work!? - # tractor.trionics.collapse_eg(), - trio.open_nursery( - strict_exception_groups=False, - ) as tn, - ): + async with trio.open_nursery() as tn: await tn.start(spawn_and_sleep_forever) if 'mp' in spawn_backend: time.sleep(0.1) os.kill(pid, signal.SIGINT) - with pytest.raises(KeyboardInterrupt): + # SIGINT -> `KeyboardInterrupt`; under `trio>=0.25`'s strict + # exception-groups the KI surfaces wrapped in a (cancel-padded) + # `BaseExceptionGroup` rather than bare — so accept either form + # (replaces the now-deprecated `strict_exception_groups=False`, + # and `collapse_eg()` can't help since the group is multi-exc: + # the KI rides alongside the child-task `Cancelled`s). + with pytest.raises(BaseException) as excinfo: trio.run(main) + exc = excinfo.value + assert ( + isinstance(exc, KeyboardInterrupt) + or ( + isinstance(exc, BaseExceptionGroup) + and exc.subgroup(KeyboardInterrupt) is not None + ) + ) async def spin_for(period=3):