Skip to content

Commit da67e0d

Browse files
MSeifert04serhiy-storchaka
authored andcommitted
bpo-29916: Include PyGetSetDef in C API extension documentation. (#831)
1 parent 11f0807 commit da67e0d

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

Doc/c-api/structures.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,43 @@ definition with the same method name.
294294
read-only access. Using :c:macro:`T_STRING` for :attr:`type` implies
295295
:c:macro:`READONLY`. Only :c:macro:`T_OBJECT` and :c:macro:`T_OBJECT_EX`
296296
members can be deleted. (They are set to *NULL*).
297+
298+
299+
.. c:type:: PyGetSetDef
300+
301+
Structure to define property-like access for a type. See also description of
302+
the :c:member:`PyTypeObject.tp_getset` slot.
303+
304+
+-------------+------------------+-----------------------------------+
305+
| Field | C Type | Meaning |
306+
+=============+==================+===================================+
307+
| name | const char \* | attribute name |
308+
+-------------+------------------+-----------------------------------+
309+
| get | getter | C Function to get the attribute |
310+
+-------------+------------------+-----------------------------------+
311+
| set | setter | optional C function to set or |
312+
| | | delete the attribute, if omitted |
313+
| | | the attribute is readonly |
314+
+-------------+------------------+-----------------------------------+
315+
| doc | const char \* | optional docstring |
316+
+-------------+------------------+-----------------------------------+
317+
| closure | void \* | optional function pointer, |
318+
| | | providing additional data for |
319+
| | | getter and setter |
320+
+-------------+------------------+-----------------------------------+
321+
322+
The ``get`` function takes one :c:type:`PyObject\*` parameter (the
323+
instance) and a function pointer (the associated ``closure``)::
324+
325+
typedef PyObject *(*getter)(PyObject *, void *);
326+
327+
It should return a new reference on success or *NULL* with a set exception
328+
on failure.
329+
330+
``set`` functions take two :c:type:`PyObject\*` parameters (the instance and
331+
the value to be set) and a function pointer (the associated ``closure``)::
332+
333+
typedef int (*setter)(PyObject *, PyObject *, void *);
334+
335+
In case the attribute should be deleted the second parameter is *NULL*.
336+
Should return ``0`` on success or ``-1`` with a set exception on failure.

Doc/c-api/typeobj.rst

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -719,21 +719,6 @@ type objects) *must* have the :attr:`ob_size` field.
719719
This field is not inherited by subtypes (computed attributes are inherited
720720
through a different mechanism).
721721

722-
.. XXX belongs elsewhere
723-
724-
Docs for PyGetSetDef::
725-
726-
typedef PyObject *(*getter)(PyObject *, void *);
727-
typedef int (*setter)(PyObject *, PyObject *, void *);
728-
729-
typedef struct PyGetSetDef {
730-
const char *name; /* attribute name */
731-
getter get; /* C function to get the attribute */
732-
setter set; /* C function to set or delete the attribute */
733-
const char *doc; /* optional doc string */
734-
void *closure; /* optional additional data for getter and setter */
735-
} PyGetSetDef;
736-
737722

738723
.. c:member:: PyTypeObject* PyTypeObject.tp_base
739724

0 commit comments

Comments
 (0)