Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 2 tasks
jakkdl opened this issue Aug 31, 2024 · 2 comments
Open
1 of 2 tasks

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

jakkdl opened this issue Aug 31, 2024 · 2 comments

Comments

@jakkdl
Copy link
Member

jakkdl commented Aug 31, 2024

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]
@jakkdl
Copy link
Member Author

jakkdl commented Sep 10, 2024

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

@jakkdl
Copy link
Member Author

jakkdl commented Sep 11, 2024

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant