[Python-Dev] PEP 492: async/await in Python; version 4
yselivanov.ml at gmail.com
Fri May 1 22:06:27 CEST 2015
On 2015-05-01 3:23 PM, Yury Selivanov wrote:
> Let's say it this way: I want to know what I am looking at
> when I browse through the code -- an asynchronous iterator,
> or a normal iterator. I want an explicit difference between
> these protocols, because they are different.
> Moreover, the below code is a perfectly valid, infinite
> class SomeIterable:
> def __iter__(self):
> return self
> async def __next__(self):
> return 'spam'
> I'm strong -1 on this idea.
To further clarify on the example:
async def __aiter__(self):
async def __next__(self):
If you pass this to 'async for' you will get
'hello' printed and the loop will be over.
If you pass this to 'for', you will get an
infinite loop, because '__next__' will return a
coroutine object (that has to be also awaited,
but it wouldn't, because it's a plain 'for'
This is something that we shouldn't let happen.
More information about the Python-Dev