跳到内容

await-outside-async (PLE1142)

添加于 v0.0.150 · 相关问题 · 查看源码

源自 Pylint 代码检查工具。

作用

检查在 async 函数外部使用 await 的情况。

为什么这不好?

async 函数外部使用 await 是语法错误。

示例

import asyncio


def foo():
    await asyncio.sleep(1)

建议改为

import asyncio


async def foo():
    await asyncio.sleep(1)

Notebook 行为

例外情况是,Jupyter notebook 的顶层允许使用 await(参见:autoawait)。

参考