Skip to content

Add aiter and anext builtin function #3609

Closed

Description

Activity

  1. Snowapril commented on Apr 14, 2022

    @Snowapril
    Contributor

    builtins.aiter can be implemented quite easy with just a few lines of code.
    but for builtins.anext, it seems anext_awaitable must be implemented first.

    static PyObject *
    builtin_anext_impl(PyObject *module, PyObject *aiterator,
                       PyObject *default_value)
    {
        // ...skip
        awaitable = (*t->tp_as_async->am_anext)(aiterator);
        if (default_value == NULL) {
            return awaitable;
        }
    
        PyObject* new_awaitable = PyAnextAwaitable_New(
                awaitable, default_value);
        Py_DECREF(awaitable);
        return new_awaitable;
    }
  2. sum12 commented on Apr 17, 2022

    @sum12
    Contributor

    Thanks for the "good for issue". I am probably misunderstanding things.
    the slots for tp_as_async->am_aiter is missing. According to cpython that would be the correct way to check if the object has __aiter__ implementaed, Is this the correct way to proceed, probably an outline of how this could be done would be great

  3. youknowone commented on Apr 18, 2022

    @youknowone
    MemberAuthor

    @sum12 you are right. that's the right way. But instead of the right way, you can implement it by calling __aiter__ directly.

    If you are interested in the right way, You can do it by looking at other slots, like IterNext or Callable. The right way would not be the 'good first issue'.

  4. sidx04 commented on May 26, 2025

    @sidx04

    hey @youknowone @sum12 @Snowapril , i see builtins.anext is still not implemented, however builtins.aiter is. is it possible for me to take on this issue? from what I have understood, I think anext calls the aiter to fetch an async iterator which is then processed in the anext func. I'm assuming I can use this as a starting point to model anext_awaitable.

    Any guidance would be appreciated!

  5. youknowone commented on Dec 25, 2025

    @youknowone
    MemberAuthor

    Thanks @sum12 and @YashSuthar983 ! this is done!

    Thanks @Snowapril for advices

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions