'await' in non-async function is a blocking error · Issue #15339 · python/mypy (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

@xiaxinmeng

Description

@xiaxinmeng

await in a function (not a async def) causes an error "errors prevented further checking". I think the expected behavior here is to assign an error code in this case rather than to halt.

To Reproduce

Run the following file with "mypy example.py":

def bar():
    return await (coro())

Expected Behavior:

MyPy does not halt checking, and it uses an error-code for "await" outside function.

Actual Behavior

Desktop/example.py:2: error: "await" outside coroutine ("async def")
Found 1 error in 1 file (errors prevented further checking)

Environment

Mypy version: 1.3.0
Python version: 3.11.3
Operating System: Ubuntu 18.04
How to install MyPy: "python3.11 -m pip install mypy"