summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-08-24 09:55:51 (GMT)
committerGuido van Rossum <guido@python.org>2001-08-24 09:55:51 (GMT)
commit91c0d8a9223ed137b9824248bd5941c1d60feafd (patch)
tree06d11fe58ef78e079ab280b8b131270dd4498115
parent75a2f85593205f48de8d88a6a8a74d4de439b87b (diff)
downloadcpython-91c0d8a9223ed137b9824248bd5941c1d60feafd.zip
cpython-91c0d8a9223ed137b9824248bd5941c1d60feafd.tar.gz
cpython-91c0d8a9223ed137b9824248bd5941c1d60feafd.tar.bz2
getset_init(): make the arguments optional.
getset_doc: add docstring.
-rw-r--r--Objects/descrobject.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 2cb28b3..a9ee2a4 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -916,10 +916,10 @@ getset_descr_set(PyObject *self, PyObject *obj, PyObject *value)
static int
getset_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- PyObject *get, *set;
+ PyObject *get = NULL, *set = NULL;
getsetobject *gs = (getsetobject *)self;
- if (!PyArg_ParseTuple(args, "OO:getset.__init__", &get, &set))
+ if (!PyArg_ParseTuple(args, "|OO:getset.__init__", &get, &set))
return -1;
if (get == Py_None)
get = NULL;
@@ -932,6 +932,14 @@ getset_init(PyObject *self, PyObject *args, PyObject *kwds)
return 0;
}
+static char getset_doc[] =
+"getset([getfunc[, setfunc]]) -> getset attribute\n"
+"Typical use to define a managed attribute x of C instances:\n"
+"class C(object):\n"
+" def getx(self): return self.__x\n"
+" def setx(self, value): self.__x = value\n"
+" x = getset(getx, setx)";
+
PyTypeObject PyGetSet_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
@@ -955,7 +963,7 @@ PyTypeObject PyGetSet_Type = {
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
+ getset_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */