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

reduce false alarms for ASYNC113 #263

Open
jakkdl opened this issue May 29, 2024 · 0 comments
Open

reduce false alarms for ASYNC113 #263

jakkdl opened this issue May 29, 2024 · 0 comments

Comments

@jakkdl
Copy link
Member

jakkdl commented May 29, 2024

Currently this will raise ASYNC113, start-soon-in-aenter:

@asynccontextmanager
async def foo():
    async with trio.open_nursery() as nursery:
        nursery.start_soon(bar)
    yield

This clearly is not susceptible to the problem of "task might not start before yielding" though, bar is not just guaranteed to start before the yield, it's even guaranteed to finish.

It should be fairly straightforward to hold potential async113 errors in @asynccontextmanagers, and only raise them if a yield is encountered later in the same nursery.

Another example:

@asynccontextmanager
async def foo():
    # do stuff
    yield
    async with trio.open_nursery() as nursery:
        nursery.start_soon(bar)

Here we can entirely ignore any start_soons after the yield, although that might get tripped up up by weird complicated logic with conditional yields. But it would also get handled by the logic of "only error if followed by yield in the same nursery" anyway, so should just go with that.

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