Skip to content
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

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

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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.

137 changes: 136 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.

65 changes: 30 additions & 35 deletions Python/sysmodule.c
Expand Up @@ -1373,19 +1373,22 @@ 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 = NULL
finalizer: object = NULL

set_asyncgen_hooks([firstiter] [, finalizer])

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=abe3687861bb9e94]*/
{
if (finalizer && finalizer != Py_None) {
if (!PyCallable_Check(finalizer)) {
PyErr_Format(PyExc_TypeError,
Expand Down Expand Up @@ -1419,12 +1422,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 @@ -1903,20 +1900,25 @@ _PySys_GetSizeOf(PyObject *o)
return (size_t)size + presize;
}

/*[clinic input]
sys.getsizeof

object: object
default as dflt: object = NULL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to use a longer name rather than a shorter one:

Suggested change
default as dflt: object = NULL
default as default_size: object = NULL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make the diff unnecessary bigger. IMO, it is better to align with the current naming.


getsizeof(object [, default]) -> int

Return the size of object in bytes.
[clinic start generated code]*/

static PyObject *
sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds)
sys_getsizeof_impl(PyObject *module, PyObject *object, PyObject *dflt)
/*[clinic end generated code: output=3f326a2f59e30975 input=d21ca2aef11d2ff4]*/
{
static char *kwlist[] = {"object", "default", 0};
size_t size;
PyObject *o, *dflt = NULL;
PyThreadState *tstate = _PyThreadState_GET();

if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof",
kwlist, &o, &dflt)) {
return NULL;
}

size = _PySys_GetSizeOf(o);
size = _PySys_GetSizeOf(object);

if (size == (size_t)-1 && _PyErr_Occurred(tstate)) {
/* Has a default value been given */
Expand All @@ -1931,11 +1933,6 @@ sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds)
return PyLong_FromSize_t(size);
}

PyDoc_STRVAR(getsizeof_doc,
"getsizeof(object [, default]) -> int\n\
\n\
Return the size of object in bytes.");

/*[clinic input]
sys.getrefcount -> Py_ssize_t

Expand Down Expand Up @@ -2512,8 +2509,7 @@ static PyMethodDef sys_methods[] = {
SYS_GETTOTALREFCOUNT_METHODDEF
SYS_GETREFCOUNT_METHODDEF
SYS_GETRECURSIONLIMIT_METHODDEF
{"getsizeof", _PyCFunction_CAST(sys_getsizeof),
METH_VARARGS | METH_KEYWORDS, getsizeof_doc},
SYS_GETSIZEOF_METHODDEF
SYS__GETFRAME_METHODDEF
SYS__GETFRAMEMODULENAME_METHODDEF
SYS_GETWINDOWSVERSION_METHODDEF
Expand All @@ -2536,8 +2532,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