Skip to content

Commit 5c06dba

Browse files
bpo-46937: convert remaining functions to AC in _weakref (GH-31705)
1 parent 496c428 commit 5c06dba

File tree

2 files changed

+73
-22
lines changed

2 files changed

+73
-22
lines changed

Modules/_weakref.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,17 @@ _weakref__remove_dead_weakref_impl(PyObject *module, PyObject *dct,
7676
}
7777

7878

79-
PyDoc_STRVAR(weakref_getweakrefs__doc__,
80-
"getweakrefs(object) -- return a list of all weak reference objects\n"
81-
"that point to 'object'.");
79+
/*[clinic input]
80+
_weakref.getweakrefs
81+
object: object
82+
/
83+
84+
Return a list of all weak reference objects pointing to 'object'.
85+
[clinic start generated code]*/
8286

8387
static PyObject *
84-
weakref_getweakrefs(PyObject *self, PyObject *object)
88+
_weakref_getweakrefs(PyObject *module, PyObject *object)
89+
/*[clinic end generated code: output=25c7731d8e011824 input=00c6d0e5d3206693]*/
8590
{
8691
PyObject *result = NULL;
8792

@@ -107,33 +112,33 @@ weakref_getweakrefs(PyObject *self, PyObject *object)
107112
}
108113

109114

110-
PyDoc_STRVAR(weakref_proxy__doc__,
111-
"proxy(object[, callback]) -- create a proxy object that weakly\n"
112-
"references 'object'. 'callback', if given, is called with a\n"
113-
"reference to the proxy when 'object' is about to be finalized.");
115+
/*[clinic input]
116+
117+
_weakref.proxy
118+
object: object
119+
callback: object(c_default="NULL") = None
120+
/
121+
122+
Create a proxy object that weakly references 'object'.
123+
124+
'callback', if given, is called with a reference to the
125+
proxy when 'object' is about to be finalized.
126+
[clinic start generated code]*/
114127

115128
static PyObject *
116-
weakref_proxy(PyObject *self, PyObject *args)
129+
_weakref_proxy_impl(PyObject *module, PyObject *object, PyObject *callback)
130+
/*[clinic end generated code: output=d68fa4ad9ea40519 input=4808adf22fd137e7]*/
117131
{
118-
PyObject *object;
119-
PyObject *callback = NULL;
120-
PyObject *result = NULL;
121-
122-
if (PyArg_UnpackTuple(args, "proxy", 1, 2, &object, &callback)) {
123-
result = PyWeakref_NewProxy(object, callback);
124-
}
125-
return result;
132+
return PyWeakref_NewProxy(object, callback);
126133
}
127134

128135

129136
static PyMethodDef
130137
weakref_functions[] = {
131138
_WEAKREF_GETWEAKREFCOUNT_METHODDEF
132139
_WEAKREF__REMOVE_DEAD_WEAKREF_METHODDEF
133-
{"getweakrefs", weakref_getweakrefs, METH_O,
134-
weakref_getweakrefs__doc__},
135-
{"proxy", weakref_proxy, METH_VARARGS,
136-
weakref_proxy__doc__},
140+
_WEAKREF_GETWEAKREFS_METHODDEF
141+
_WEAKREF_PROXY_METHODDEF
137142
{NULL, NULL, 0, NULL}
138143
};
139144

Modules/clinic/_weakref.c.h

Lines changed: 47 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)