classification
Title: aiter() and anext() built-in functions
Type: Stage:
Components: Library (Lib) Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Jelle Zijlstra, davide.rizzo, gvanrossum, jmehnle, yselivanov
Priority: normal Keywords:

Created on 2017-10-24 13:26 by davide.rizzo, last changed 2018-06-14 15:10 by yselivanov.

Files
File name Uploaded Description Edit
aiter_comp.py davide.rizzo, 2017-10-27 09:52 tentative Python implementation
Messages (7)
msg304910 - (view) Author: Davide Rizzo (davide.rizzo) * Date: 2017-10-24 13:26
PEP 525 suggested that adding aiter() and anext() would need to wait until async __aiter__ is dropped in 3.7. Issue 31709 solved that, so now it would be possible to add them.
msg304923 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-10-24 16:17
Guido, do we need a PEP to add aiter() and anext() builtins?
msg304924 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2017-10-24 16:24
> do we need a PEP to add aiter() and anext() builtins?

No, just this tracker issue, a PR and a reviewer. (Sorry, I can't review
CPython code myself any more.)
msg304926 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-10-24 16:25
> No, just this tracker issue, a PR and a reviewer. (Sorry, I can't review
CPython code myself any more.)

Alright, I'll work on a PR after PEP 55x.
msg305107 - (view) Author: Davide Rizzo (davide.rizzo) * Date: 2017-10-27 09:52
I attempted to make a Python implementation (attached) to use in my code. There are a few questions in the comments.

One of the complications is the async equivalent of next with two arguments like next(iterator, default). It cannot return the result of __anext__() because it needs to catch StopAsyncIteration. So it should return an awaitable wrapper instead (in my Python code this is rendered as a coroutine). A secondary question is whether the default value should be returned as it is passed, or awaited on.
msg319519 - (view) Author: Jelle Zijlstra (Jelle Zijlstra) * (Python triager) Date: 2018-06-14 14:51
Do these really need to be builtins?

They seem too specialized to be widely useful; I've personally never needed them in any async code I've written. It would make more sense to me to put them in a module like operators.
msg319520 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-06-14 15:10
> Do these really need to be builtins?

We're only beginning to see async iterators being used in the wild, so we can't have a definitive answer at this point.

> They seem too specialized to be widely useful; I've personally never needed them in any async code I've written. It would make more sense to me to put them in a module like operators.

I think putting them to the operators module makes sense, at least for 3.8.  Do you want to work on a pull request?
History
Date User Action Args
2018-06-14 15:10:54yselivanovsetmessages: + msg319520
2018-06-14 14:51:41Jelle Zijlstrasetnosy: + Jelle Zijlstra
messages: + msg319519
2018-06-13 00:22:00jmehnlesetnosy: + jmehnle
2017-10-27 09:52:53davide.rizzosetfiles: + aiter_comp.py

messages: + msg305107
2017-10-24 16:25:26yselivanovsetmessages: + msg304926
2017-10-24 16:24:34gvanrossumsetmessages: + msg304924
2017-10-24 16:17:13yselivanovsetmessages: + msg304923
2017-10-24 16:10:26davide.rizzosetnosy: + gvanrossum, yselivanov
2017-10-24 13:26:15davide.rizzocreate