mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-31861: Add aiter and anext to builtins (#23847)
Co-authored-by: jab <jab@users.noreply.github.com> Co-authored-by: Daniel Pope <mauve@mauveweb.co.uk> Co-authored-by: Justin Wang <justin39@gmail.com>
This commit is contained in:
parent
94faa0724f
commit
f0a6fde882
10 changed files with 373 additions and 28 deletions
46
Python/clinic/bltinmodule.c.h
generated
46
Python/clinic/bltinmodule.c.h
generated
|
@ -530,6 +530,50 @@ PyDoc_STRVAR(builtin_hex__doc__,
|
|||
#define BUILTIN_HEX_METHODDEF \
|
||||
{"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
|
||||
|
||||
PyDoc_STRVAR(builtin_aiter__doc__,
|
||||
"aiter($module, async_iterable, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return an AsyncIterator for an AsyncIterable object.");
|
||||
|
||||
#define BUILTIN_AITER_METHODDEF \
|
||||
{"aiter", (PyCFunction)builtin_aiter, METH_O, builtin_aiter__doc__},
|
||||
|
||||
PyDoc_STRVAR(builtin_anext__doc__,
|
||||
"anext($module, aiterator, default=<unrepresentable>, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return the next item from the async iterator.");
|
||||
|
||||
#define BUILTIN_ANEXT_METHODDEF \
|
||||
{"anext", (PyCFunction)(void(*)(void))builtin_anext, METH_FASTCALL, builtin_anext__doc__},
|
||||
|
||||
static PyObject *
|
||||
builtin_anext_impl(PyObject *module, PyObject *aiterator,
|
||||
PyObject *default_value);
|
||||
|
||||
static PyObject *
|
||||
builtin_anext(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *aiterator;
|
||||
PyObject *default_value = NULL;
|
||||
|
||||
if (!_PyArg_CheckPositional("anext", nargs, 1, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
aiterator = args[0];
|
||||
if (nargs < 2) {
|
||||
goto skip_optional;
|
||||
}
|
||||
default_value = args[1];
|
||||
skip_optional:
|
||||
return_value = builtin_anext_impl(module, aiterator, default_value);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(builtin_len__doc__,
|
||||
"len($module, obj, /)\n"
|
||||
"--\n"
|
||||
|
@ -830,4 +874,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=e2fcf0201790367c input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=da9ae459e9233259 input=a9049054013a1b77]*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue