[Python-Dev] PEP 492: async/await in Python; version 4 (original) (raw)
Stefan Behnel stefan_ml at behnel.de
Fri May 1 14:39:21 CEST 2015
- Previous message (by thread): [Python-Dev] PEP 492: async/await in Python; version 4
- Next message (by thread): [Python-Dev] PEP 492: async/await in Python; version 4
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Yury Selivanov schrieb am 30.04.2015 um 03:30:
Asynchronous Iterators and "async for" --------------------------------------
An asynchronous iterable is able to call asynchronous code in its iter implementation, and asynchronous iterator can call asynchronous code in its next method. To support asynchronous iteration: 1. An object must implement an
_aiter_
method returning an awaitable resulting in an asynchronous iterator object. 2. An asynchronous iterator object must implement an_anext_
method returning an awaitable. 3. To stop iteration_anext_
must raise aStopAsyncIteration
exception.
What this section does not explain, AFAICT, nor the section on design considerations, is why the iterator protocol needs to be duplicated entirely. Can't we just assume (or even validate) that any 'regular' iterator returned from "aiter()" (as opposed to "iter()") properly obeys to the new protocol? Why additionally duplicate "next()" and "StopIteration"?
ISTM that all this really depends on is that "next()" returns an awaitable. Renaming the method doesn't help with that guarantee.
Stefan
- Previous message (by thread): [Python-Dev] PEP 492: async/await in Python; version 4
- Next message (by thread): [Python-Dev] PEP 492: async/await in Python; version 4
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]