summaryrefslogtreecommitdiffstats
path: root/Objects/descrobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-09-20 21:45:26 (GMT)
committerGuido van Rossum <guido@python.org>2001-09-20 21:45:26 (GMT)
commit32d34c809f5971f79462dcb7d0f536d46e624acc (patch)
tree29d97883adf68d8112d55c94eca8f4fb93048628 /Objects/descrobject.c
parenta56b42b1ba646170d5476e8925c56e2266b37f98 (diff)
downloadcpython-32d34c809f5971f79462dcb7d0f536d46e624acc.zip
cpython-32d34c809f5971f79462dcb7d0f536d46e624acc.tar.gz
cpython-32d34c809f5971f79462dcb7d0f536d46e624acc.tar.bz2
Add optional docstrings to getset descriptors. Fortunately, there's
no backwards compatibility to worry about, so I just pushed the 'closure' struct member to the back -- it's never used in the current code base (I may eliminate it, but that's more work because the getter and setter signatures would have to change.) As examples, I added actual docstrings to the getset attributes of a few types: file.closed, xxsubtype.spamdict.state.
Diffstat (limited to 'Objects/descrobject.c')
-rw-r--r--Objects/descrobject.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index dfbb3b6..7be1074 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -26,7 +26,7 @@ typedef struct {
typedef struct {
COMMON;
- struct getsetlist *d_getset;
+ PyGetSetDef *d_getset;
} PyGetSetDescrObject;
typedef struct {
@@ -302,7 +302,7 @@ static PyMemberDef descr_members[] = {
{0}
};
-static struct getsetlist method_getset[] = {
+static PyGetSetDef method_getset[] = {
{"__doc__", (getter)method_get_doc},
{0}
};
@@ -317,12 +317,27 @@ member_get_doc(PyMemberDescrObject *descr, void *closure)
return PyString_FromString(descr->d_member->doc);
}
-static struct getsetlist member_getset[] = {
+static PyGetSetDef member_getset[] = {
{"__doc__", (getter)member_get_doc},
{0}
};
static PyObject *
+getset_get_doc(PyGetSetDescrObject *descr, void *closure)
+{
+ if (descr->d_getset->doc == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return PyString_FromString(descr->d_getset->doc);
+}
+
+static PyGetSetDef getset_getset[] = {
+ {"__doc__", (getter)getset_get_doc},
+ {0}
+};
+
+static PyObject *
wrapper_get_doc(PyWrapperDescrObject *descr, void *closure)
{
if (descr->d_base->doc == NULL) {
@@ -332,7 +347,7 @@ wrapper_get_doc(PyWrapperDescrObject *descr, void *closure)
return PyString_FromString(descr->d_base->doc);
}
-static struct getsetlist wrapper_getset[] = {
+static PyGetSetDef wrapper_getset[] = {
{"__doc__", (getter)wrapper_get_doc},
{0}
};
@@ -444,7 +459,7 @@ static PyTypeObject PyGetSetDescr_Type = {
0, /* tp_iternext */
0, /* tp_methods */
descr_members, /* tp_members */
- 0, /* tp_getset */
+ getset_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
(descrgetfunc)getset_get, /* tp_descr_get */
@@ -532,7 +547,7 @@ PyDescr_NewMember(PyTypeObject *type, PyMemberDef *member)
}
PyObject *
-PyDescr_NewGetSet(PyTypeObject *type, struct getsetlist *getset)
+PyDescr_NewGetSet(PyTypeObject *type, PyGetSetDef *getset)
{
PyGetSetDescrObject *descr;
@@ -778,7 +793,7 @@ wrapper_doc(wrapperobject *wp)
}
}
-static struct getsetlist wrapper_getsets[] = {
+static PyGetSetDef wrapper_getsets[] = {
{"__name__", (getter)wrapper_name},
{"__doc__", (getter)wrapper_doc},
{0}