[Python-checkins] python/dist/src/Objects typeobject.c,2.126.4.7,2.126.4.8
gvanrossum@sourceforge.net
gvanrossum@sourceforge.net
Wed, 17 Apr 2002 17:36:19 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv9531
Modified Files:
Tag: release22-maint
typeobject.c
Log Message:
Backport rev 2.143 (note: some earlier bugfix candidates still TBD).
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.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.126.4.7
retrieving revision 2.126.4.8
diff -C2 -d -r2.126.4.7 -r2.126.4.8
*** typeobject.c 8 Apr 2002 01:39:56 -0000 2.126.4.7
--- typeobject.c 18 Apr 2002 00:36:17 -0000 2.126.4.8
***************
*** 84,96 ****
{
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;
}
--- 84,100 ----
{
PyObject *result;
! if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL)
return PyString_FromString(type->tp_doc);
result = PyDict_GetItemString(type->tp_dict, "__doc__");
! 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;
}