python-trio / flake8-async

Highly opinionated linter for Trio code
https://flake8-async.readthedocs.io
MIT License
17 stars 2 forks source link

ASYNC912: timeout/cancelscope with only conditional checkpoints #242

Closed jakkdl closed 1 month ago

jakkdl commented 2 months ago

oh, turns out #183 was already planning on using ASYNC912.

It looks like I broke some stuff, but I gotta go for the day so I thought I'd push in case you have time to review tests/eval_files/async912.py and have any opinions on the behavior in some of the edge cases in there.

jakkdl commented 2 months ago

Got the major shit working, but needs some cleanup, comments, documentation and a self-review pass. So no need to review yet.

jakkdl commented 1 month ago

Added a couple corner cases, I don't think wrapping calls is terribly common - but if it is feel free to open an issue and I'll make it search for the matching calls differently.

    # wrapped calls do not raise errors
    with customWrapper(trio.fail_at(10)):
        ...
    with (res := trio.fail_at(10)):
        ...
    # but saving with `as` does
    with trio.fail_at(10) as res:  # ASYNC912: 9
        if bar():
            await trio.lowlevel.checkpoint()