From d20305bd779f39fbcfdf6e97dc417b769faa2810 Mon Sep 17 00:00:00 2001 From: Nova Date: Tue, 14 Oct 2025 14:19:16 -0700 Subject: [PATCH 1/2] ASYNC120 docs --- docs/rules.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/rules.rst b/docs/rules.rst index afc7943..1b86acd 100644 --- a/docs/rules.rst +++ b/docs/rules.rst @@ -85,6 +85,17 @@ _`ASYNC120` : await-in-except If this checkpoint is cancelled, the current active exception will be replaced by the ``Cancelled`` exception, and cannot be reraised later. This will not trigger when :ref:`ASYNC102 ` does, and if you don't care about losing non-cancelled exceptions you could disable this rule. This is currently not able to detect asyncio shields. + + To handle this correctly, use a shielded cancel scope with a timeout:: + + try: + await process() + except Exception: + with trio.fail_after(seconds, shield=True): + await cleanup() + raise + + The shield prevents cancellation from replacing the current exception, while the timeout ensures cleanup can't block indefinitely. Use :func:`trio.move_on_after` if you want to suppress timeout errors rather than raise them. _`ASYNC121`: control-flow-in-taskgroup `return`, `continue`, and `break` inside a :ref:`taskgroup_nursery` can lead to counterintuitive behaviour. Refactor the code to instead cancel the :ref:`cancel_scope` inside the TaskGroup/Nursery and place the statement outside of the TaskGroup/Nursery block. In asyncio a user might expect the statement to have an immediate effect, but it will wait for all tasks to finish before having an effect. See `Trio issue #1493 `_ for further issues specific to trio/anyio. From d67fc70b14d76c37eeb043e56d62201642eb78e3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Oct 2025 21:19:37 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/rules.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/rules.rst b/docs/rules.rst index 1b86acd..81643a4 100644 --- a/docs/rules.rst +++ b/docs/rules.rst @@ -85,16 +85,16 @@ _`ASYNC120` : await-in-except If this checkpoint is cancelled, the current active exception will be replaced by the ``Cancelled`` exception, and cannot be reraised later. This will not trigger when :ref:`ASYNC102 ` does, and if you don't care about losing non-cancelled exceptions you could disable this rule. This is currently not able to detect asyncio shields. - + To handle this correctly, use a shielded cancel scope with a timeout:: - + try: await process() except Exception: with trio.fail_after(seconds, shield=True): await cleanup() raise - + The shield prevents cancellation from replacing the current exception, while the timeout ensures cleanup can't block indefinitely. Use :func:`trio.move_on_after` if you want to suppress timeout errors rather than raise them. _`ASYNC121`: control-flow-in-taskgroup