| 1 |
.. highlight:: c |
| 2 |
|
| 3 |
.. _descriptor-objects: |
| 4 |
|
| 5 |
Descriptor Objects |
| 6 |
------------------ |
| 7 |
|
| 8 |
"Descriptors" are objects that describe some attribute of an object. They are |
| 9 |
found in the dictionary of type objects. |
| 10 |
|
| 11 |
.. XXX document these! |
| 12 |
|
| 13 |
.. c:var:: PyTypeObject PyProperty_Type |
| 14 |
|
| 15 |
The type object for the built-in descriptor types. |
| 16 |
|
| 17 |
|
| 18 |
.. c:function:: PyObject* PyDescr_NewGetSet(PyTypeObject *type, struct PyGetSetDef *getset) |
| 19 |
|
| 20 |
|
| 21 |
.. c:function:: PyObject* PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *meth) |
| 22 |
|
| 23 |
|
| 24 |
.. c:var:: PyTypeObject PyMemberDescr_Type |
| 25 |
|
| 26 |
The type object for member descriptor objects created from |
| 27 |
:c:type:`PyMemberDef` structures. These descriptors expose fields of a |
| 28 |
C struct as attributes on a type, and correspond |
| 29 |
to :class:`types.MemberDescriptorType` objects in Python. |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
.. c:var:: PyTypeObject PyGetSetDescr_Type |
| 34 |
|
| 35 |
The type object for get/set descriptor objects created from |
| 36 |
:c:type:`PyGetSetDef` structures. These descriptors implement attributes |
| 37 |
whose value is computed by C getter and setter functions, and are used |
| 38 |
for many built-in type attributes. |
| 39 |
|
| 40 |
|
| 41 |
.. c:function:: PyObject* PyDescr_NewMethod(PyTypeObject *type, struct PyMethodDef *meth) |
| 42 |
|
| 43 |
|
| 44 |
.. c:var:: PyTypeObject PyMethodDescr_Type |
| 45 |
|
| 46 |
The type object for method descriptor objects created from |
| 47 |
:c:type:`PyMethodDef` structures. These descriptors expose C functions as |
| 48 |
methods on a type, and correspond to :class:`types.MemberDescriptorType` |
| 49 |
objects in Python. |
| 50 |
|
| 51 |
|
| 52 |
.. c:function:: PyObject* PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *wrapper, void *wrapped) |
| 53 |
|
| 54 |
|
| 55 |
.. c:var:: PyTypeObject PyWrapperDescr_Type |
| 56 |
|
| 57 |
The type object for wrapper descriptor objects created by |
| 58 |
:c:func:`PyDescr_NewWrapper` and :c:func:`PyWrapper_New`. Wrapper |
| 59 |
descriptors are used internally to expose special methods implemented |
| 60 |
via wrapper structures, and appear in Python as |
| 61 |
:class:`types.WrapperDescriptorType` objects. |
| 62 |
|
| 63 |
|
| 64 |
.. c:function:: PyObject* PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method) |
| 65 |
|
| 66 |
|
| 67 |
.. c:function:: int PyDescr_IsData(PyObject *descr) |
| 68 |
|
| 69 |
Return non-zero if the descriptor object *descr* describes a data attribute, or |
| 70 |
``0`` if it describes a method. *descr* must be a descriptor object; there is |
| 71 |
no error checking. |
| 72 |
|
| 73 |
|
| 74 |
.. c:function:: PyObject* PyWrapper_New(PyObject *, PyObject *) |
| 75 |
|
| 76 |
|
| 77 |
Built-in descriptors |
| 78 |
^^^^^^^^^^^^^^^^^^^^ |
| 79 |
|
| 80 |
.. c:var:: PyTypeObject PySuper_Type |
| 81 |
|
| 82 |
The type object for super objects. This is the same object as |
| 83 |
:class:`super` in the Python layer. |
| 84 |
|
| 85 |
|
| 86 |
.. c:var:: PyTypeObject PyClassMethod_Type |
| 87 |
|
| 88 |
The type of class method objects. This is the same object as |
| 89 |
:class:`classmethod` in the Python layer. |
| 90 |
|
| 91 |
|
| 92 |
.. c:var:: PyTypeObject PyClassMethodDescr_Type |
| 93 |
|
| 94 |
The type object for C-level class method descriptor objects. |
| 95 |
This is the type of the descriptors created for :func:`classmethod` defined in |
| 96 |
C extension types, and is the same object as :class:`classmethod` |
| 97 |
in Python. |
| 98 |
|
| 99 |
|
| 100 |
.. c:function:: PyObject *PyClassMethod_New(PyObject *callable) |
| 101 |
|
| 102 |
Create a new :class:`classmethod` object wrapping *callable*. |
| 103 |
*callable* must be a callable object and must not be ``NULL``. |
| 104 |
|
| 105 |
On success, this function returns a :term:`strong reference` to a new class |
| 106 |
method descriptor. On failure, this function returns ``NULL`` with an |
| 107 |
exception set. |
| 108 |
|
| 109 |
|
| 110 |
.. c:var:: PyTypeObject PyStaticMethod_Type |
| 111 |
|
| 112 |
The type of static method objects. This is the same object as |
| 113 |
:class:`staticmethod` in the Python layer. |
| 114 |
|
| 115 |
|
| 116 |
.. c:function:: PyObject *PyStaticMethod_New(PyObject *callable) |
| 117 |
|
| 118 |
Create a new :class:`staticmethod` object wrapping *callable*. |
| 119 |
*callable* must be a callable object and must not be ``NULL``. |
| 120 |
|
| 121 |
On success, this function returns a :term:`strong reference` to a new static |
| 122 |
method descriptor. On failure, this function returns ``NULL`` with an |
| 123 |
exception set. |
| 124 |
|