Add `aiter` and `anext` builtin function
Feature
- [x]
builtins.aiter: https://docs.python.org/3/library/functions.html#aiter #3646 - [ ]
builtins.anext: https://docs.python.org/3/library/functions.html#anext (See @Snowapril 's comment)
Python Documentation
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;
}
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
@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'.
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!