[issue31192] "return await coro()" SyntaxError despite being "valid syntax" in PEP 492

Martin Panter report at bugs.python.org
Sun Aug 13 01:49:02 EDT 2017


Martin Panter added the comment:

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>)'

----------
nosy: +martin.panter
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue31192>
_______________________________________


More information about the Python-bugs-list mailing list