@@ -8,18 +8,36 @@ Descriptor Objects
88"Descriptors" are objects that describe some attribute of an object. They are
99found in the dictionary of type objects.
1010
11- .. XXX document these!
12-
1311.. c :var :: PyTypeObject PyProperty_Type
1412
1513 The type object for the built-in descriptor types.
1614
1715
1816.. c :function :: PyObject* PyDescr_NewGetSet (PyTypeObject *type, struct PyGetSetDef *getset)
1917
18+ Create a new get-set descriptor for extension type *type * from the
19+ :c:type: `PyGetSetDef ` structure *getset *.
20+
21+ Get-set descriptors expose attributes implemented by C getter and setter
22+ functions rather than stored directly in the instance. This is the same kind
23+ of descriptor created for entries in :c:member: `~PyTypeObject.tp_getset `, and
24+ it appears in Python as a :class: `types.GetSetDescriptorType ` object.
25+
26+ On success, return a :term: `strong reference ` to the descriptor. Return
27+ ``NULL `` with an exception set on failure.
28+
29+ .. c :function :: PyObject* PyDescr_NewMember (PyTypeObject *type, struct PyMemberDef *member)
30+
31+ Create a new member descriptor for extension type *type * from the
32+ :c:type: `PyMemberDef ` structure *member *.
2033
21- .. c :function :: PyObject* PyDescr_NewMember (PyTypeObject *type, struct PyMemberDef *meth)
34+ Member descriptors expose fields in the type's C struct as Python
35+ attributes. This is the same kind of descriptor created for entries in
36+ :c:member: `~PyTypeObject.tp_members `, and it appears in Python as a
37+ :class: `types.MemberDescriptorType ` object.
2238
39+ On success, return a :term: `strong reference ` to the descriptor. Return
40+ ``NULL `` with an exception set on failure.
2341
2442.. c :var :: PyTypeObject PyMemberDescr_Type
2543
@@ -35,22 +53,53 @@ found in the dictionary of type objects.
3553 The type object for get/set descriptor objects created from
3654 :c:type: `PyGetSetDef ` structures. These descriptors implement attributes
3755 whose value is computed by C getter and setter functions, and are used
38- for many built-in type attributes.
56+ for many built-in type attributes. They correspond to
57+ :class: `types.GetSetDescriptorType ` objects in Python.
3958
4059
4160.. c :function :: PyObject* PyDescr_NewMethod (PyTypeObject *type, struct PyMethodDef *meth)
4261
62+ Create a new method descriptor for extension type *type * from the
63+ :c:type: `PyMethodDef ` structure *meth *.
64+
65+ Method descriptors expose C functions as methods on a type. This is the same
66+ kind of descriptor created for entries in
67+ :c:member: `~PyTypeObject.tp_methods `, and it appears in Python as a
68+ :class: `types.MethodDescriptorType ` object.
69+
70+ On success, return a :term: `strong reference ` to the descriptor. Return
71+ ``NULL `` with an exception set on failure.
4372
4473.. c :var :: PyTypeObject PyMethodDescr_Type
4574
4675 The type object for method descriptor objects created from
4776 :c:type: `PyMethodDef ` structures. These descriptors expose C functions as
48- methods on a type, and correspond to :class: `types.MemberDescriptorType `
77+ methods on a type, and correspond to :class: `types.MethodDescriptorType `
4978 objects in Python.
5079
5180
52- .. c :function :: PyObject* PyDescr_NewWrapper (PyTypeObject *type, struct wrapperbase *wrapper, void *wrapped)
81+ .. c :struct :: wrapperbase
82+
83+ Describes a slot wrapper used by :c:func: `PyDescr_NewWrapper `.
84+
85+ Each ``wrapperbase `` record stores the Python-visible name and metadata for a
86+ special method implemented by a type slot, together with the wrapper
87+ function used to adapt that slot to Python's calling convention.
5388
89+ .. c :function :: PyObject* PyDescr_NewWrapper (PyTypeObject *type, struct wrapperbase *base, void *wrapped)
90+
91+ Create a new wrapper descriptor for extension type *type * from the
92+ :c:struct: `wrapperbase ` structure *base * and the wrapped slot function
93+ pointer
94+ *wrapped *.
95+
96+ Wrapper descriptors expose special methods implemented by type slots. This
97+ is the same kind of descriptor that CPython creates for slot-based special
98+ methods such as ``__repr__ `` or ``__add__ ``, and it appears in Python as a
99+ :class: `types.WrapperDescriptorType ` object.
100+
101+ On success, return a :term: `strong reference ` to the descriptor. Return
102+ ``NULL `` with an exception set on failure.
54103
55104.. c :var :: PyTypeObject PyWrapperDescr_Type
56105
@@ -63,6 +112,16 @@ found in the dictionary of type objects.
63112
64113.. c :function :: PyObject* PyDescr_NewClassMethod (PyTypeObject *type, PyMethodDef *method)
65114
115+ Create a new class method descriptor for extension type *type * from the
116+ :c:type: `PyMethodDef ` structure *method *.
117+
118+ Class method descriptors expose C methods that receive the class rather than
119+ an instance when accessed. This is the same kind of descriptor created for
120+ ``METH_CLASS `` entries in :c:member: `~PyTypeObject.tp_methods `, and it
121+ appears in Python as a :class: `types.ClassMethodDescriptorType ` object.
122+
123+ On success, return a :term: `strong reference ` to the descriptor. Return
124+ ``NULL `` with an exception set on failure.
66125
67126.. c :function :: int PyDescr_IsData (PyObject *descr)
68127
@@ -71,8 +130,18 @@ found in the dictionary of type objects.
71130 no error checking.
72131
73132
74- .. c :function :: PyObject* PyWrapper_New (PyObject *, PyObject *)
133+ .. c :function :: PyObject* PyWrapper_New (PyObject *d, PyObject *self)
134+
135+ Create a new bound wrapper object from the wrapper descriptor *d * and the
136+ instance *self *.
75137
138+ This is the bound form of a wrapper descriptor created by
139+ :c:func: `PyDescr_NewWrapper `. CPython creates these objects when a slot
140+ wrapper is accessed through an instance, and they appear in Python as
141+ :class: `types.MethodWrapperType ` objects.
142+
143+ On success, return a :term: `strong reference ` to the wrapper object. Return
144+ ``NULL `` with an exception set on failure.
76145
77146Built-in descriptors
78147^^^^^^^^^^^^^^^^^^^^
@@ -92,9 +161,9 @@ Built-in descriptors
92161.. c :var :: PyTypeObject PyClassMethodDescr_Type
93162
94163 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.
164+ This is the type of the descriptors created for :func: `classmethod ` defined
165+ in C extension types, and corresponds to
166+ :class: ` types.ClassMethodDescriptorType ` objects in Python.
98167
99168
100169.. c :function :: PyObject *PyClassMethod_New (PyObject *callable)
@@ -121,4 +190,3 @@ Built-in descriptors
121190 On success, this function returns a :term: `strong reference ` to a new static
122191 method descriptor. On failure, this function returns ``NULL `` with an
123192 exception set.
124-
0 commit comments