classification
Title: add aiter() and anext() functions to operator module
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Jelle Zijlstra, davide.rizzo, giampaolo.rodola, jab, jmehnle, yselivanov
Priority: normal Keywords: patch

Created on 2017-10-24 13:26 by davide.rizzo, last changed 2018-08-24 16:30 by jab.

Files
File name Uploaded Description Edit
aiter_comp.py davide.rizzo, 2017-10-27 09:52 tentative Python implementation
Pull Requests
URL Status Linked Edit
PR 8895 open jab, 2018-08-24 04:56
Messages (10)
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?
msg323989 - (view) Author: Joshua Bronson (jab) * Date: 2018-08-24 04:57
Updating the issue title to reflect the decision to add these to the operator module rather than to built-ins.

Submitted a PR here: https://github.com/python/cpython/pull/8895
msg323997 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-08-24 11:18
Great, thanks! There's someone working on a pr to add them as builtins (so that pr is in C). I'll have to take a look when i'm back from vacation at that pr too, before we can make a decision. 

I've been to europython, pycon ru, and pybay conferences recently and the number of people who want these as builtins was surprisingly high.
msg324009 - (view) Author: Joshua Bronson (jab) * Date: 2018-08-24 16:30
Interesting, thanks Yury!

I only saw the discussion here which implied these wouldn't go directly into builtins for 3.8 (and I searched here and in GitHub, and couldn't find the PR you mentioned either), so I'm curious if that was tracked somewhere. It'd be unfortunate if the work I did on that PR couldn't be used, but I'd be even happier to have these as builtins.

Thanks again for reviewing when you're back, and have a wonderful vacation in the meantime!
History
Date User Action Args
2018-08-24 16:30:52jabsetmessages: + msg324009
2018-08-24 15:52:29gvanrossumsetnosy: - gvanrossum
2018-08-24 11:18:08yselivanovsetmessages: + msg323997
2018-08-24 04:57:32jabsetmessages: + msg323989
title: aiter() and anext() built-in functions -> add aiter() and anext() functions to operator module
2018-08-24 04:56:02jabsetkeywords: + patch
stage: patch review
pull_requests: + pull_request8368
2018-06-25 06:03:43giampaolo.rodolasetnosy: + giampaolo.rodola
2018-06-24 19:39:27jabsetnosy: + jab
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