python-trio / flake8-async

Highly opinionated linter for Trio code
https://flake8-async.readthedocs.io
MIT License
19 stars 2 forks source link

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

Open jakkdl opened 2 months ago

jakkdl commented 2 months ago

https://github.com/python-trio/flake8-async/blob/225f15a98db4bb8ce4600127fd0fe90bc5c9c04b/tests/eval_files/async102.py#L117-L125

TODO:

jakkdl commented 1 month ago

The other rules that could be relevant are:

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 commented 1 month ago

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.