summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-04-18 00:22:00 (GMT)
committerGuido van Rossum <guido@python.org>2002-04-18 00:22:00 (GMT)
commit6ca7d41c1f0f2f6ef654f3ff6241c80cccf06ab3 (patch)
treeafd1673b0face9658322fa096ed28941cd03693e /Objects
parenta90a3b471de133df411e947d8a498e7965f6d800 (diff)
downloadcpython-6ca7d41c1f0f2f6ef654f3ff6241c80cccf06ab3.zip
cpython-6ca7d41c1f0f2f6ef654f3ff6241c80cccf06ab3.tar.gz
cpython-6ca7d41c1f0f2f6ef654f3ff6241c80cccf06ab3.tar.bz2
SF bug 542984.
Change type_get_doc (the get function for __doc__) to look in tp_dict more often, and if it finds a descriptor in tp_dict, to call it (with a NULL instance). This means you can add a __doc__ descriptor to a new-style class that returns instance docs when called on an instance, and class docs when called on a class -- or the same docs in either case, but lazily computed. I'll also check this into the 2.2 maintenance branch.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index deb7320..f647d57 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -82,15 +82,19 @@ 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;
- }
+ if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL)
return PyString_FromString(type->tp_doc);
- }
result = PyDict_GetItemString(type->tp_dict, "__doc__");
- Py_INCREF(result);
+ if (result == NULL) {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+ else if (result->ob_type->tp_descr_get) {
+ result = result->ob_type->tp_descr_get(result, NULL, type);
+ }
+ else {
+ Py_INCREF(result);
+ }
return result;
}