A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2015-May/139764.html below:

[Python-Dev] PEP 492: async/await in Python; version 4

[Python-Dev] PEP 492: async/await in Python; version 4 [Python-Dev] PEP 492: async/await in Python; version 4Yury Selivanov 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
> 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
More information about the Python-Dev mailing list

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