You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ASYNC100: A with trio.fail_after(...): or with trio.move_on_after(...):
context does not contain any await statements. This makes it pointless, as
the timeout can only be triggered by a checkpoint.
ASYNC116: trio.sleep() with >24 hour interval should usually be trio.sleep_forever().
there's no asyncio.sleep_forever() as far as I can tell.
The only blocker for autofixing 9xx in asyncio is some minor test infrastructure, as we can insert asyncio.sleep(0) instead of library.lowlevel.checkpoint(). [No longer blocked by test infra]
ASYNC111: Variable, from context manager opened inside nursery, passed to start[_soon] might be invalidly accessed while in use, due to context manager closing before the nursery. This is usually a bug, and nurseries should generally be the inner-most context manager.
ASYNC112: Nursery body with only a call to nursery.start[_soon] and not passing itself as a parameter can be replaced with a regular function call.
ASYNC101: yield inside a nursery or cancel scope is only safe when implementing a context manager - otherwise, it breaks exception handling.
One part that leaves me somewhat confused about implementing ASYNC113 is what, if anything, to do about ASYNC114. Currently we gate ASYNC113 to only warn on startable methods, presumably to reduce false positives when you don't care about the background task being properly up and running. But I don't think there's any way to differentiate those for asyncio tasks, so we're left with the options of:
Always warn on all calls
Only warn for calls specified in startable_in_context_manager.
If startable_in_context_manager was expanded to support wildcards, we could get the best of both worlds by telling asyncio users to specify * if they want the former behaviour. (this would also allow anyio/trio users to go maximum defensiveness, in case they're starting functions not defined in code that could trigger ASYNC114, or they might've forgotten to add task_status to functions)
Another problem is that since there's no .start()-equivalent that guarantees that the task has been started, there's no standardized way of alleviating the problem that we could detect, so users are left to handle it in whatever way they can, and then noqa the warning.
Activity
Zac-HD commentedon Feb 25, 2024
I don't think we should support other libraries - curio is no longer being updated, twisted is more callback than async, others are even smaller.
jakkdl commentedon Feb 26, 2024
partial
finally:orexcept BaseException/trio.Cancelledunless you use a shielded cancel scope with a timeout.ASYNC119when using an async context manager in an async generator #211, and asyncio does have https://docs.python.org/3/library/asyncio-task.html#asyncio.shield + https://docs.python.org/3/library/asyncio-task.html#timeoutsASYNC119when using an async context manager in an async generator #211 (comment)todo
while <condition>: await trio.sleep()should be replaced by atrio.Event.asyncio.Eventtimeoutparameter - usetrio.[fail/move_on]_[after/at]insteadwith trio.fail_after(...):orwith trio.move_on_after(...):context does not contain any
awaitstatements. This makes it pointless, asthe timeout can only be triggered by a checkpoint.
asyncio.timeout,asyncio.timeout_at,ASYNC116:trio.sleep()with >24 hour interval should usually betrio.sleep_forever().asyncio.sleep_forever()as far as I can tell.asyncio.sleep(0)instead oflibrary.lowlevel.checkpoint(). [No longer blocked by test infra]tracked in #215
start[_soon]might be invalidly accessed while in use, due to context manager closing before the nursery. This is usually a bug, and nurseries should generally be the inner-most context manager.nursery.start[_soon]and not passing itself as a parameter can be replaced with a regular function call.yieldinside a nursery or cancel scope is only safe when implementing a context manager - otherwise, it breaks exception handling.jakkdl commentedon May 16, 2024
start_soon.[this comment previously talked about ASYNC111, but async support for 111 was already implemented at the time of posting 😕 ]
jakkdl commentedon May 29, 2024
One part that leaves me somewhat confused about implementing ASYNC113 is what, if anything, to do about ASYNC114. Currently we gate ASYNC113 to only warn on startable methods, presumably to reduce false positives when you don't care about the background task being properly up and running. But I don't think there's any way to differentiate those for asyncio tasks, so we're left with the options of:
startable_in_context_manager.If
startable_in_context_managerwas expanded to support wildcards, we could get the best of both worlds by telling asyncio users to specify*if they want the former behaviour. (this would also allow anyio/trio users to go maximum defensiveness, in case they're starting functions not defined in code that could trigger ASYNC114, or they might've forgotten to addtask_statusto functions)Another problem is that since there's no
.start()-equivalent that guarantees that the task has been started, there's no standardized way of alleviating the problem that we could detect, so users are left to handle it in whatever way they can, and thennoqathe warning.