This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: "return await coro()" SyntaxError despite being "valid syntax" in PEP 492
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: martin.panter, merrellb
Priority: normal Keywords:

Created on 2017-08-13 04:58 by merrellb, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg300209 - (view) Author: Brian (merrellb) Date: 2017-08-13 04:58
PEP 492 lists the following under "valid syntax" and yet 3.5.2 raises a SyntaxError:

def foo():
    return await coro()

but this works:

def bar():
    return await (coro())
msg300212 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2017-08-13 05:49
In 3.5, “await” is an ordinary identifier outside of “async def” functions. You have to use the “async def” syntax to enable it as a special keyword.

>>> async def foo():  # “Async def” enables “await” as a keyword
...     return await coro()  # Valid syntax
... 
>>> async def coro(): pass
... 
>>> def await(c):
...     c.close()  # Avoid RuntimeWarning
...     return "Called await({!r})".format(c)
... 
>>> def bar():  # Ordinary non-PEP-492 function
...     return await (coro())
... 
>>> bar()
'Called await(<coroutine object coro at 0x7fb82c50d410>)'
History
Date User Action Args
2022-04-11 14:58:50adminsetgithub: 75375
2017-08-13 05:49:02martin.pantersetstatus: open -> closed

nosy: + martin.panter
messages: + msg300212

resolution: not a bug
stage: resolved
2017-08-13 04:58:12merrellbcreate