Skip to content

Add aiter and anext builtin function #3609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 2 tasks
youknowone opened this issue Apr 14, 2022 · 3 comments
Open
1 of 2 tasks

Add aiter and anext builtin function #3609

youknowone opened this issue Apr 14, 2022 · 3 comments
Labels

Comments

@youknowone
Copy link
Member

youknowone commented Apr 14, 2022

Feature

Python Documentation

@Snowapril
Copy link
Contributor

Snowapril commented Apr 14, 2022

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;
}

@sum12
Copy link
Contributor

sum12 commented Apr 17, 2022

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

@youknowone
Copy link
Member Author

@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'.

sum12 added a commit to sum12/RustPython that referenced this issue Apr 19, 2022
sum12 added a commit to sum12/RustPython that referenced this issue Apr 19, 2022
the caller is expected to make sure that the passed in object does in
fact supports the protocol

relates RustPython#3609
@sum12 sum12 mentioned this issue Apr 19, 2022
sum12 added a commit to sum12/RustPython that referenced this issue Apr 21, 2022
the caller is expected to make sure that the passed in object does in
fact supports the protocol

relates RustPython#3609
@youknowone youknowone removed the good first issue Good for newcomers label Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants