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
iterable:

    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:

    class SomeIterable:
         def __iter__(self):
             return self
         async def __aiter__(self):
             return self
         async def __next__(self):
             print('hello')
             raise StopAsyncIteration


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

This is something that we shouldn't let happen.

Yury
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to