flake8-async

25.7.1 · active · verified Thu Apr 16

flake8-async is a highly opinionated Flake8 plugin designed to identify common problems, potential bugs, dead code, performance issues, and idiom violations specific to asynchronous programming with Trio, AnyIO, and asyncio. It is actively maintained, with frequent releases following a CalVer (YY.month.patch) scheme. The plugin integrates with the standard `flake8` tool and some of its checks are also incorporated into the `ruff` linter.

Common errors

Warnings

Install

Quickstart

To use flake8-async, install it and then run the `flake8` command on your Python files. The plugin will automatically detect and report issues. This example demonstrates a `busy_wait_function` that would trigger the `ASYNC110` warning, which suggests replacing `await trio.sleep()` in a `while` loop with an event-based mechanism for better efficiency.

import trio

async def busy_wait_function():
    done = False
    while not done:
        await trio.sleep(0.001) # ASYNC110: async-busy-wait
        # In a real scenario, 'done' would be set by some other async operation

async def main():
    async with trio.open_nursery() as nursery:
        nursery.start_soon(busy_wait_function)

if __name__ == '__main__':
    # To run flake8-async, save this as a .py file (e.g., 'my_async_code.py')
    # and then run: flake8 my_async_code.py
    # It should report ASYNC110.
    pass

view raw JSON →