[New-bugs-announce] [issue45768] SyntaxError: 'await' outside function" in "asyncio-task.html#waiting-primitives" code snippets

Jose Ville report at bugs.python.org
Tue Nov 9 12:39:33 EST 2021


New submission from Jose Ville <joseville>:

https://docs.python.org/3/library/asyncio-task.html#asyncio.wait has the following two code snippets both of which fail with ""SyntaxError: 'await' outside function" when I run them in Python 3.9.7

Snippet 1:

```
async def foo():
    return 42

coro = foo()
done, pending = await asyncio.wait({coro})

if coro in done:
    # This branch will never be run!
    pass # I added this to prevent IndentationError
```

Snippet 2:

```
async def foo():
    return 42

task = asyncio.create_task(foo())
done, pending = await asyncio.wait({task})

if task in done:
    # Everything will work as expected now.
    pass # I added this to prevent IndentationError
```

----------
messages: 406032
nosy: joseville
priority: normal
severity: normal
status: open
title: SyntaxError: 'await' outside function" in "asyncio-task.html#waiting-primitives" code snippets

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45768>
_______________________________________


More information about the New-bugs-announce mailing list