← 输入框|github.com|刷新
Skip to content

add aiter() and anext() functions #76042

Closed

Description

@sorcio
mannequin
BPO 31861
Nosy @gvanrossum, @vstinner, @basak, @jab, @sorcio, @dimaqq, @1st1, @JelleZijlstra, @pablogsal, @isidentical, @belm0, @jack1142, @sweeneyde
PRs
  • bpo-31861: Add operator.aiter and operator.anext #8895
  • bpo-31861: Provide aiter and anext builtins #23847
  • bpo-31861: Complete the C-API docs for PyObject_GetAiter and PyAiter_Check #25004
  • bpo-31861: Fix possible crash in PyAnextAwaitable_New #25005
  • bpo-31861: Fix reference leak in builtin_anext_impl() #25008
  • Files
  • aiter_comp.py: tentative Python implementation
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-03-24.01:43:07.674>
    created_at = <Date 2017-10-24.13:26:15.573>
    labels = ['library', '3.10']
    title = 'add aiter() and anext() functions'
    updated_at = <Date 2021-04-07.22:59:05.539>
    user = 'https://github.com/sorcio'

    bugs.python.org fields:

    activity = <Date 2021-04-07.22:59:05.539>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-03-24.01:43:07.674>
    closer = 'pablogsal'
    components = ['Library (Lib)']
    creation = <Date 2017-10-24.13:26:15.573>
    creator = 'davide.rizzo'
    dependencies = []
    files = ['47242']
    hgrepos = []
    issue_num = 31861
    keywords = ['patch']
    message_count = 25.0
    messages = ['304910', '304923', '304924', '304926', '305107', '319519', '319520', '323989', '323997', '324009', '337061', '337135', '375633', '380408', '381832', '383327', '383441', '389414', '389417', '389420', '389422', '389426', '389427', '390402', '390495']
    nosy_count = 15.0
    nosy_names = ['gvanrossum', 'vstinner', 'rb', 'jab', 'davide.rizzo', 'jmehnle', 'Dima.Tisnek', 'yselivanov', 'JelleZijlstra', 'pablogsal', 'BTaskaya', 'Eric Wieser', 'John Belmonte', 'jack1142', 'Dennis Sweeney']
    pr_nums = ['8895', '23847', '25004', '25005', '25008']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue31861'
    versions = ['Python 3.10']

    Activity

    1. sorcio commented on Oct 24, 2017

      sorciomannequin
      MannequinAuthor

      PEP-525 suggested that adding aiter() and anext() would need to wait until async __aiter__ is dropped in 3.7. bpo-31709 solved that, so now it would be possible to add them.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Oct 24, 2017
    3. 1st1 commented on Oct 24, 2017

      @1st1
      Member

      Guido, do we need a PEP to add aiter() and anext() builtins?

    4. gvanrossum commented on Oct 24, 2017

      @gvanrossum
      Member

      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.)

    5. 1st1 commented on Oct 24, 2017

      @1st1
      Member

      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.

    6. sorcio commented on Oct 27, 2017

      sorciomannequin
      MannequinAuthor

      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.

    7. JelleZijlstra commented on Jun 14, 2018

      @JelleZijlstra
      Member

      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.

    8. 1st1 commented on Jun 14, 2018

      @1st1
      Member

      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?

    9. jab commented on Aug 24, 2018

      jabmannequin
      Mannequin

      Updating the issue title to reflect the decision to add these to the operator module rather than to built-ins.

      Submitted a PR here: #8895

    10. changed the title [-]aiter() and anext() built-in functions[/-] [+]add aiter() and anext() functions to operator module[/+] on Aug 24, 2018
    11. 1st1 commented on Aug 24, 2018

      @1st1
      Member

      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.

    12. jab commented on Aug 24, 2018

      jabmannequin
      Mannequin

      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!

    13. dimaqq commented on Mar 4, 2019

      dimaqqmannequin
      Mannequin

      https://www.python.org/dev/peps/pep-0525/#aiter-and-anext-builtins kinda promised aiter and anext built-ins.

      This ticket seems idle.

      Perhaps it's time for the decider club to either remove that language from PEP-525 or make a plan for aiter/anext?

    14. 7 remaining items

    15. jab commented on Dec 18, 2020

      jabmannequin
      Mannequin

      Please see #23847 for the C implementation of aiter and anext added to builtins, as requested.

    16. changed the title [-]add aiter() and anext() functions to operator module[/-] [+]add aiter() and anext() functions[/+] on Dec 18, 2020
    17. isidentical commented on Dec 20, 2020

      @isidentical
      SponsorMember

      I don't have anything to add to this beside the name choice is safe and won't clash with anything (but honestly I would prefer it to be discussed on the ML before implementing something after 3 years). I checked a limited dataset to search for aiter and only found examples from 2 different projects. Elastic have something for themselves and the other usages are coming from the tests of aioitertools.
      https://github.com/elastic/elasticsearch-py/blob/5fe9ff721ce493fbf2fc8b94d5ab02fc7e55fd5a/elasticsearch/_async/helpers.py#L85-L96

    18. gvanrossum commented on Mar 23, 2021

      @gvanrossum
      Member

      New changeset f0a6fde by Joshua Bronson in branch 'master':
      bpo-31861: Add aiter and anext to builtins (bpo-23847)
      f0a6fde

    19. pablogsal commented on Mar 23, 2021

      @pablogsal
      Member

      New changeset d969202 by Pablo Galindo in branch 'master':
      bpo-31861: Complete the C-API docs for PyObject_GetAiter and PyAiter_Check (GH-25004)
      d969202

    20. pablogsal commented on Mar 24, 2021

      @pablogsal
      Member

      New changeset 919d42d by Pablo Galindo in branch 'master':
      bpo-31861: Fix possible crash in PyAnextAwaitable_New (GH-25005)
      919d42d

    21. vstinner commented on Mar 24, 2021

      @vstinner
      Member

      I reopen the issue.

      The commit f0a6fde introduced a reference leak:

      $ ./python -m test -R 3:3 test_asyncgen

      0:00:00 load avg: 4.75 Run tests sequentially
      0:00:00 load avg: 4.75 [1/1] test_asyncgen
      beginning 6 repetitions
      123456
      ......
      test_asyncgen leaked [72, 72, 72] references, sum=216
      test_asyncgen leaked [30, 30, 30] memory blocks, sum=90
      test_asyncgen failed

      == Tests result: FAILURE ==

      1 test failed:
      test_asyncgen

      Total duration: 6.0 sec
      Tests result: FAILURE

    22. pablogsal commented on Mar 24, 2021

      @pablogsal
      Member

      New changeset a02683a by Pablo Galindo in branch 'master':
      bpo-31861: Fix reference leak in builtin_anext_impl() (GH-25008)
      a02683a

    23. pablogsal commented on Mar 24, 2021

      @pablogsal
      Member

      Fixed by PR25008

    24. sweeneyde commented on Apr 7, 2021

      @sweeneyde
      Member

      A bug was reported in anext(): https://bugs.python.org/issue43751

    25. vstinner commented on Apr 7, 2021

      @vstinner
      Member

      I proposed to PR 25266 to rename PyAnextAwaitable_Type to _PyAnextAwaitable_Type, and to initialize the type at Python startup: can someone please have a look?

    26. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions