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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4