summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-03-17 18:57:07 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-03-17 18:57:07 (GMT)
commit4d761f2443e3e60d386ff956c20cbc69b96d4511 (patch)
tree617fd910440e699acfedb102f8c77824fbf9fdcf /Objects
parentbf69e0c3abf9392979f4b880c0c931d5cf53af78 (diff)
downloadcpython-4d761f2443e3e60d386ff956c20cbc69b96d4511.zip
cpython-4d761f2443e3e60d386ff956c20cbc69b96d4511.tar.gz
cpython-4d761f2443e3e60d386ff956c20cbc69b96d4511.tar.bz2
SF patch 530070: pydoc regression, from Martin and Guido.
Change the way __doc__ is handled, to avoid blowing up on non-string __doc__ values.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index ca7e64d..c938f52 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -79,10 +79,27 @@ type_dict(PyTypeObject *type, void *context)
return PyDictProxy_New(type->tp_dict);
}
+static PyObject *
+type_get_doc(PyTypeObject *type, void *context)
+{
+ PyObject *result;
+ if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
+ if (type->tp_doc == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return PyString_FromString(type->tp_doc);
+ }
+ result = PyDict_GetItemString(type->tp_dict, "__doc__");
+ Py_INCREF(result);
+ return result;
+}
+
static PyGetSetDef type_getsets[] = {
{"__name__", (getter)type_name, NULL, NULL},
{"__module__", (getter)type_module, (setter)type_set_module, NULL},
{"__dict__", (getter)type_dict, NULL, NULL},
+ {"__doc__", (getter)type_get_doc, NULL, NULL},
{0}
};
@@ -1079,9 +1096,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
}
/* Set tp_doc to a copy of dict['__doc__'], if the latter is there
- and is a string. Note that the tp_doc slot will only be used
- by C code -- python code will use the version in tp_dict, so
- it isn't that important that non string __doc__'s are ignored.
+ and is a string. The __doc__ accessor will first look for tp_doc;
+ if that fails, it will still look into __dict__.
*/
{
PyObject *doc = PyDict_GetItemString(dict, "__doc__");