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

Stefan Behnel stefan_ml at behnel.de
Sun May 3 08:32:02 CEST 2015


Stefan Behnel schrieb am 02.05.2015 um 06:54:
> Yury Selivanov schrieb am 01.05.2015 um 20:52:
>> I don't like the idea of combining __next__ and __anext__.
> 
> Ok, fair enough. So, how would you use this new protocol manually then?
> Say, I already know that I won't need to await the next item that the
> iterator will return. For normal iterators, I could just call next() on it
> and continue the for-loop. How would I do it for AIterators?

BTW, I guess that this "AIterator", or rather "AsyncIterator", needs to be
a separate protocol (and ABC) then. Implementing "__aiter__()" and
"__anext__()" seems perfectly reasonable without implementing (or using) a
Coroutine.

That means we also need an "AsyncIterable" as a base class for it.

Would Coroutine then inherit from both Iterator and AsyncIterator? Or
should we try to separate the protocol hierarchy completely? The section on
"Coroutine objects" seems to suggest that inheritance from Iterator is not
intended.

OTOH, I'm not sure if inheriting from AsyncIterator is intended for
Coroutine. The latter might just be a stand-alone ABC with
send/throw/close, after all.

I think that in order to get a better understanding of the protocol(s) that
this PEP proposes, and the terminology that it should use, it would help to
implement these ABCs.

That might even help us to decide if we need new builtins (or helpers)
aiter() and anext() in order to deal with these protocols.

Stefan




More information about the Python-Dev mailing list