python-trio / flake8-async

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

New rule: no guaranteed checkpoint in infinite loop #240

Closed jakkdl closed 1 month ago

jakkdl commented 2 months ago
# this raises 910
async def no_checkpoint():
    if ...:
        await trio.sleep("1")
# and this
async def no_checkpoint():
    while bar():
        if ...:
            await trio.sleep("1")
# but not this
async def no_checkpoint():
    while True:
        if ...:
            await trio.sleep("1")

same for try/except.

The problem likely stems from the fact that the function never returns, and as such it never returns without checkpointing - which is where 910 would trigger. Found it while exploring #227, and would be particularly problematic if/when expanding ASYNC100 to use Visitor91x.

jakkdl commented 2 months ago

A possible solution is adding a dedicated rule for "[infinite] loop without checkpoint in loop body", see https://github.com/python-trio/flake8-async/issues/227#issuecomment-2088298232