Skip to content

ASYNC102 await-in-finally-or-cancelled false alarms on nurseries #283

Open

Description

@jakkdl

try:
pass
finally:
# false alarm, open_nursery does not block/checkpoint on entry.
async with trio.open_nursery() as nursery: # error: 8, Statement("try/finally", lineno-4)
nursery.cancel_scope.deadline = trio.current_time() + 10
nursery.cancel_scope.shield = True
# false alarm, we currently don't handle nursery.cancel_scope.[deadline/shield]
await foo() # error: 12, Statement("try/finally", lineno-8)

TODO:

  • Special-case async with open_nursery(...), and async with anyio.create_task_group(...) as not being checkpoints. (also affects other rules)
  • handle [nursery_name].cancel_scope.[deadline/shield]

Activity

  1. jakkdl commented on Sep 10, 2024

    @jakkdl
    MemberAuthor

    The other rules that could be relevant are:

    • ASYNC100 cancel-scope-no-checkpoint
      • A cancel scope with only a nursery can never be cancelled, so this should ignore open_nursery/create_task_group
    • ASYNC120 await-in-except
    • ASYNC91x
      • nurseries can checkpoint, so these should not ignore nurseries, and do not need to be changed.
    async def foo(): # should not give ASYNC910
      async with trio.open_nursery() as nursery():
        nursery.start_soon(bar)

    tl;dr, ASYNC100 also needs changing

  2. jakkdl commented on Sep 11, 2024

    @jakkdl
    MemberAuthor

    Hrm, neither of these statements are cancellation sources

    my_nursery = await trio.open_nursery()
    async with my_nursery:
        ...

    So it's not just async with trio.open_nursery() that needs to be checked against.
    Both of those cases are definitely less common, but far from unheard of. The former is an easy fix, the latter is a bit more tricky but we're already type-tracking nurseries for other reasons so shouldn't be too bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    rule improvementImprovement for currently existing rule

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions