-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Ideas for flake8-trio
checks
#1
Comments
For #1, python-trio/trio#264 has a |
Nurseries, and |
|
Is this about looking at the function signature async def foo(timeout): # error
... or function calls with a timeout keyword? (excluding calls to the trio library) foo(timeout=15) # error or both? |
is the for i in range(...):
...
if ...:
await trio.sleep(...)
... |
Function definitions - nothing wrong with using the API available to you, but for user-controlled code Trio's idiomatic cancellation scopes are so much nicer.
Let's go with "any |
Should there be a checkpoint before the first yield? |
Oops, yes, there should be; see #17 (review) |
Would be nice if you made a comment here (or somewhere) when updating the task list - I get no notification when you edit it otherwise. |
Oops, will do! |
All current Tasks now have pull requests associated with them, and #8 is merged already. |
Added one last task based on a suggestion in the upstream issue 🙂 |
All done 🎉 |
As a "list of ideas" issue, any of the ideas below might turn out to be too difficult to implement, or in fact counterproductive if implemented. Nonetheless, we need somewhere to dump ideas and this issue is that place. Items are in rough priority order by a combination of estimated importance and tractability.
yield
inside a nursery or cancel scopeTrio101: Never yield inside a nursery or cancel scope #4
await
s inside afinally:
clause needs shielding and a timeout, e.g.with trio.fail_after(1, shield=True):
(source) (also applies toasync for
orasync with
)Trio102: await inside finally needs shielding and timeout #5
except Cancelled
orexcept BaseException
block with a code path that doesn't re-raise
the error.Trio103: except Cancelled/BaseException must be re-raised #8
await
ing it. Per the discussion here typecheckers have some support for the (difficult!) general case, but it's easy and useful to make a list of all Trio functions and check for e.g.trio.sleep(0)
without anawait
. We don't need to checkasync for
orasync with
because using the sync syntax is a noisy error at runtime, unlike the checkpoint warnings.TRIO105: Calling trio async function without await #10
trio
namespace in a way that isn't justimport trio
(this is really just to make the linter easier to implement, but it's consistent with ~99% of existing usage anyway)Add 106, don't fancy import trio #11
await
,async for
, orasync with
) on every code path, unless an exception is raised (the same rule that Trio internals follow)6: async checkpoints #16
yield
) should have at least one checkpoint in each loop iteration, and an additional checkpoint after the last iteration (unless an exception is raised, again like the Trio internals)7: async iterables must checkpoint after yields #17
TRIO102
- you need a shielded cancel scope toawait
inside anexcept Cancelled/BaseException
block, not justfinally:
Extend 102 to excepts, 104 also catch yield #18
timeout
parameter - encourage use oftrio.fail_after()
ortrio.move_on_after()
instead. (httpx
does OK here, but most uses are IMO a design mistake)Add trio[300], async functions should not have a timeout parameter #20
trio.Event
rather than sleeping in a loop. Concretely I think matchingwhile not <expr>: await trio.sleep(...)
might work well here?10: add trio[301], don't await trio.sleep inside loop #21
outermostinnermost. (actually pretty complicated?)Add trio111, passing variables from context managers to nurseries opened outside them #22
nursery.start[_soon]
("consider using a regular function call instead"), unlessnursery
is passed as an argument to the start-soon'd function.TRIO112: replace one-line nursery with regular function call #34
The text was updated successfully, but these errors were encountered: