Skip to content

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Sep 28, 2025

% ruff rule ASYNC115

async-zero-sleep (ASYNC115)

Derived from the flake8-async linter.

Fix is always available.

What it does

Checks for uses of trio.sleep(0) or anyio.sleep(0).

Why is this bad?

trio.sleep(0) is equivalent to calling trio.lowlevel.checkpoint().
However, the latter better conveys the intent of the code.

Example

import trio


async def func():
    await trio.sleep(0)

Use instead:

import trio


async def func():
    await trio.lowlevel.checkpoint()

Fix safety

This rule's fix is marked as unsafe if there's comments in the
trio.sleep(0) expression, as comments may be removed.

For example, the fix would be marked as unsafe in the following case:

import trio


async def func():
    await trio.sleep(  # comment
        # comment
        0
    )

@cclauss cclauss force-pushed the ruff branch 2 times, most recently from 1213f15 to 3940a3a Compare September 28, 2025 14:22
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

Successfully merging this pull request may close these issues.

2 participants