Skip to content

Ideas for flake8-trio checks #1

Closed

Description

@Zac-HD

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.

Activity

  1. jakkdl commented on Jul 17, 2022

    @jakkdl
    Member

    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?

  2. Zac-HD commented on Jul 17, 2022

    @Zac-HD
    MemberAuthor

    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 👍

  3. jakkdl commented on Jul 27, 2022

    @jakkdl
    Member

    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.

  4. jakkdl commented on Jul 30, 2022

    @jakkdl
    Member

    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?

  5. jakkdl commented on Jul 30, 2022

    @jakkdl
    Member

    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(...)
      ...
  6. Zac-HD commented on Jul 30, 2022

    @Zac-HD
    MemberAuthor

    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'.

  7. jakkdl commented on Jul 30, 2022

    @jakkdl
    Member

    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?

  8. Zac-HD commented on Jul 31, 2022

    @Zac-HD
    MemberAuthor

    That's allowed but not required.

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

  9. jakkdl commented on Aug 2, 2022

    @jakkdl
    Member

    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.

  10. Zac-HD commented on Aug 2, 2022

    @Zac-HD
    MemberAuthor

    Oops, will do!

  11. jakkdl commented on Aug 5, 2022

    @jakkdl
    Member

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

  12. Zac-HD commented on Aug 5, 2022

    @Zac-HD
    MemberAuthor

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

  13. Zac-HD commented on Aug 11, 2022

    @Zac-HD
    MemberAuthor

    All done 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions