[issue39562] Asynchronous comprehensions don't work in asyncio REPL

jack1142 report at bugs.python.org
Wed Feb 5 12:28:25 EST 2020


New submission from jack1142 <kuba.kuczys at gmail.com>:

asyncio REPL doesn't allow using asynchronous comprehensions outside of async func. Same behavior can also be observed when using `ast.PyCF_ALLOW_TOP_LEVEL_AWAIT` flag in `compile()`

Example with `async for`:
>>> async def async_gen():
...     for x in range(5):
...         yield await asyncio.sleep(1, x)
... 
>>> [x async for x in async_gen()]
  File "<console>", line 0
SyntaxError: asynchronous comprehension outside of an asynchronous function


Example with `await`:
>>> [await asyncio.sleep(1, x) for x in range(5)]
  File "<console>", line 0
SyntaxError: asynchronous comprehension outside of an asynchronous function

----------
components: asyncio
messages: 361443
nosy: asvetlov, jack1142, yselivanov
priority: normal
severity: normal
status: open
title: Asynchronous comprehensions don't work in asyncio REPL
type: behavior
versions: Python 3.8, Python 3.9

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


More information about the Python-bugs-list mailing list