Skip to content

gh-103131: Convert sys.set_asyncgen_hooks to AC #103132

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ always available.
``'opcode'`` event type added; :attr:`~frame.f_trace_lines` and
:attr:`~frame.f_trace_opcodes` attributes added to frames

.. function:: set_asyncgen_hooks([firstiter] [, finalizer])
.. function:: set_asyncgen_hooks(*, firstiter=None, finalizer=None)

Accepts two optional keyword arguments which are callables that accept an
:term:`asynchronous generator iterator` as an argument. The *firstiter*
Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ struct _Py_global_strings {
STRUCT_FOR_ID(filter)
STRUCT_FOR_ID(filters)
STRUCT_FOR_ID(final)
STRUCT_FOR_ID(finalizer)
STRUCT_FOR_ID(find_class)
STRUCT_FOR_ID(firstiter)
STRUCT_FOR_ID(fix_imports)
STRUCT_FOR_ID(flags)
STRUCT_FOR_ID(flush)
Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 69 additions & 1 deletion Python/clinic/sysmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 13 additions & 19 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1373,19 +1373,20 @@ static PyStructSequence_Desc asyncgen_hooks_desc = {
2
};

static PyObject *
sys_set_asyncgen_hooks(PyObject *self, PyObject *args, PyObject *kw)
{
static char *keywords[] = {"firstiter", "finalizer", NULL};
PyObject *firstiter = NULL;
PyObject *finalizer = NULL;
/*[clinic input]
sys.set_asyncgen_hooks

if (!PyArg_ParseTupleAndKeywords(
args, kw, "|OO", keywords,
&firstiter, &finalizer)) {
return NULL;
}
firstiter: object = None
finalizer: object = None

Set a finalizer for async generators objects.
[clinic start generated code]*/

static PyObject *
sys_set_asyncgen_hooks_impl(PyObject *module, PyObject *firstiter,
PyObject *finalizer)
/*[clinic end generated code: output=6fe3b2dd3f9a9db5 input=3664f349bc833d43]*/
{
if (finalizer && finalizer != Py_None) {
if (!PyCallable_Check(finalizer)) {
PyErr_Format(PyExc_TypeError,
Expand Down Expand Up @@ -1419,12 +1420,6 @@ sys_set_asyncgen_hooks(PyObject *self, PyObject *args, PyObject *kw)
Py_RETURN_NONE;
}

PyDoc_STRVAR(set_asyncgen_hooks_doc,
"set_asyncgen_hooks([firstiter] [, finalizer])\n\
\n\
Set a finalizer for async generators objects."
);

/*[clinic input]
sys.get_asyncgen_hooks

Expand Down Expand Up @@ -2536,8 +2531,7 @@ static PyMethodDef sys_methods[] = {
SYS__DEBUGMALLOCSTATS_METHODDEF
SYS_SET_COROUTINE_ORIGIN_TRACKING_DEPTH_METHODDEF
SYS_GET_COROUTINE_ORIGIN_TRACKING_DEPTH_METHODDEF
{"set_asyncgen_hooks", _PyCFunction_CAST(sys_set_asyncgen_hooks),
METH_VARARGS | METH_KEYWORDS, set_asyncgen_hooks_doc},
SYS_SET_ASYNCGEN_HOOKS_METHODDEF
SYS_GET_ASYNCGEN_HOOKS_METHODDEF
SYS_GETANDROIDAPILEVEL_METHODDEF
SYS_ACTIVATE_STACK_TRAMPOLINE_METHODDEF
Expand Down