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

Ideas for flake8-trio checks #1

Closed
12 tasks done
Zac-HD opened this issue Jul 17, 2022 · 13 comments
Closed
12 tasks done

Ideas for flake8-trio checks #1

Zac-HD opened this issue Jul 17, 2022 · 13 comments

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Jul 17, 2022

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.

@jakkdl
Copy link
Member

jakkdl commented Jul 17, 2022

For #1, python-trio/trio#264 has a trio.open_cancel_scope which I can't find in the docs. So I'm guessing that's removed, and as such we only care about yielding in nurseries?
Must this include a check that it's not within a @contextmanager or an @asynccontextmanager?

@Zac-HD
Copy link
Member Author

Zac-HD commented Jul 17, 2022

Nurseries, and trio.{fail,move_on}_{at,after}(), yeah. And yep, we'll want to check for the presence of a context-manager decorator to avoid false alarms 👍

@jakkdl
Copy link
Member

jakkdl commented Jul 27, 2022

Possibly support import trio as <foo> and from trio import * with varying levels of sophistication (assume everything called e.g. open_nursery is from trio, vs parse the imports) depending on need.
Warning if user tries to import trio as <foo> or from trio import <> since that is unsupported.

@jakkdl
Copy link
Member

jakkdl commented Jul 30, 2022

Async functions should not have a timeout parameter - use trio.fail_after() or trio.move_on_after() instead. (httpx does OK here, but most uses are IMO a design mistake)

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?

@jakkdl
Copy link
Member

jakkdl commented Jul 30, 2022

Prefer waiting on a trio.Event rather than sleeping in a loop. Concretely I think matching while not <expr>: await trio.sleep(...) might work well here?

is the not in the loop condition significant? Or should any calls to await trio.sleep(...) inside loops be errors?
the latter feels like it might send a lot of false alarms?

for i in range(...):
  ...
  if ...:
    await trio.sleep(...)
  ...

@Zac-HD
Copy link
Member Author

Zac-HD commented Jul 30, 2022

Is this about looking at the function signature [...] or function calls with a timeout keyword?

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.

Prefer waiting on a trio.Event rather than sleeping in a loop. Concretely I think matching while not <expr>: await trio.sleep(...) might work well here?

is the not in the loop condition significant? Or should any calls to await trio.sleep(...) inside loops be errors? the latter feels like it might send a lot of false alarms?

Let's go with "any while loop where the body consists entirely of await trio.sleep[_until](...)". It's a pretty narrow check that way, but it's part of a useful category I think of as 'docs presented as you need them'.

@jakkdl
Copy link
Member

jakkdl commented Jul 30, 2022

Async iterables (i.e. with a 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)

Should there be a checkpoint before the first yield?

@Zac-HD
Copy link
Member Author

Zac-HD commented Jul 31, 2022

That's allowed but not required.

Oops, yes, there should be; see #17 (review)

@jakkdl
Copy link
Member

jakkdl commented Aug 2, 2022

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.

@Zac-HD
Copy link
Member Author

Zac-HD commented Aug 2, 2022

Oops, will do!

@jakkdl
Copy link
Member

jakkdl commented Aug 5, 2022

All current Tasks now have pull requests associated with them, and #8 is merged already.

@Zac-HD
Copy link
Member Author

Zac-HD commented Aug 5, 2022

Added one last task based on a suggestion in the upstream issue 🙂

@Zac-HD
Copy link
Member Author

Zac-HD commented Aug 11, 2022

All done 🎉

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

2 participants