Skip to content

Commit e9d9ed2

Browse files
committed
Add "how to" for the getter Argument Clinic directive.
1 parent a9aaedf commit e9d9ed2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

development-tools/clinic.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,43 @@ The generated glue code looks like this:
20012001
.. versionadded:: 3.13
20022002

20032003

2004+
.. _clinic-howto-getter:
2005+
2006+
How to generate getter with Argument Clinic
2007+
--------------------------------------------
2008+
2009+
You can use ``@getter`` directive to generate "impl" function
2010+
to defining getter.
2011+
2012+
Example from :cpy-file:`Modules/_io/bufferedio.c`::
2013+
2014+
/*[clinic input]
2015+
@critical_section
2016+
@getter
2017+
_io._Buffered.closed
2018+
[clinic start generated code]*/
2019+
2020+
The generate glue code looks like this.
2021+
Note that this example is mixture usage with ``@critical_section`` directive
2022+
to achieve thread safety without causing deadlocks between threads:
2023+
2024+
.. code-block:: c
2025+
2026+
static PyObject *
2027+
_io__Buffered_closed_get(buffered *self, void *context)
2028+
{
2029+
PyObject *return_value = NULL;
2030+
2031+
Py_BEGIN_CRITICAL_SECTION(self);
2032+
return_value = _io__Buffered_closed_get_impl(self);
2033+
Py_END_CRITICAL_SECTION();
2034+
2035+
return return_value;
2036+
}
2037+
2038+
.. versionadded:: 3.13
2039+
2040+
20042041
.. _clinic-howto-deprecate-positional:
20052042
.. _clinic-howto-deprecate-keyword:
20062043

0 commit comments

Comments
 (0)