New submission from Ivan Levkivskyi <levkivs...@gmail.com>:

PEP 530 is not very clear about `await` in generator expressions. But when I 
try it, the error is a bit confusing:

>>> async def g(i):
...     print(i)
... 
>>> async def f():
...     result = list(await g(i) for i in range(3))
...     print(result)
... 
>>> f().send(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in f
TypeError: 'async_generator' object is not iterable

At the same time a (seemingly) equivalent list comprehension works fine:

>>> async def f():
...     result = [await g(i) for i in range(3)]
...     print(result)
... 
>>> f().send(None)
0
1
2
[None, None, None]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration

I would say that the first case should either behave as a second one, or raise 
a syntax error.

Or is it actually an intended behavior?

----------
components: Interpreter Core
messages: 306732
nosy: levkivskyi, yselivanov
priority: normal
severity: normal
status: open
title: Strange behavior with await in a generator expression
type: behavior
versions: Python 3.6, Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32113>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to