跳到内容

trio-sync-call (ASYNC105)

派生自 flake8-async linter。

有时提供修复。

作用

检查对未立即等待的 trio 函数的调用。

为什么这不好?

trio 公开的许多函数都是异步的,必须等待才能生效。 在没有 await 的情况下调用 trio 函数可能会导致 RuntimeWarning 诊断和意外行为。

示例

import trio


async def double_sleep(x):
    trio.sleep(2 * x)

建议改为

import trio


async def double_sleep(x):
    await trio.sleep(2 * x)

修复安全性

此规则的修复被标记为不安全,因为将 await 添加到函数调用会更改其语义和运行时行为。