Issue1605006

classification
Title: __doc__ descriptor on new style class returned directly
Type: Severity: normal
Components: Core Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, leouserz, pjenvey
Priority: normal Keywords:

Created on 2006-11-29.04:47:44 by cgroves, last changed 2008-06-08.22:56:17 by pjenvey.

Messages
msg1328 (view) Author: Charlie Groves (cgroves) Date: 2006-11-29.04:47:44
A descriptor assigned to __doc__ on a new style class is returned directly instead of having its __get__ method called.  This causes docdescriptor in test_descr.py to fail.  Interestingly, the same descriptor on an instance of the class has its __get__ called.  Only classes are screwed up.
msg1329 (view) Author: Deleted User leouserz (leouserz) Date: 2007-01-19.01:28:43
This appears to be happening because the object returned by "__doc__" is a PyGetSetDescr.  This in turn is queried for the doc value which calls getDoc.  This in turn appears to return the DocDescriptor without any subsequent calls.  Im not sure which is the right fix is yet:
1. Fix getDoc to check for a descriptor? 
2. Instrument PyType type___findattr so that it does something different with doc?
3. When __doc__ is set with a descriptor, replace the default descriptor?
4. etc...

PyClass interacts correctly with the descriptor, yet it has a different set of logic so Im not sure if there is anything to emulate there.


Another question is if the DocDescr should be detectable as a decsriptor?  It does not appear to state that it is when isDataDescr is invoked.  Maybe this too is a bug or Im not seeing the code straight at this moment....

leouser
msg1330 (view) Author: Deleted User leouserz (leouserz) Date: 2007-01-19.14:43:17
small note, it appears that python has ran into the same problem in the past:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=542984&group_id=5470

leouser
msg1331 (view) Author: Deleted User leouserz (leouserz) Date: 2007-01-19.16:00:30
ok,

it appears that python's implementation has special getDoc code for this situation:
static PyObject *
type_get_doc(PyTypeObject *type, void *context)
{
	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,
						       (PyObject *)type);
	}
	else {
		Py_INCREF(result);
	}
	return result;
}
http://svn.python.org/view/python/trunk/Objects/typeobject.c?rev=52245&view=markup

By overriding the getDoc for PyType we can add an additional check for a "__get__" implementation.  If not null we call __get__ on the return value.

There is a patch for this up here:
http://sourceforge.net/tracker/index.php?func=detail&aid=1639663&group_id=12867&atid=312867

leouser
msg3259 (view) Author: Philip Jenvey (pjenvey) Date: 2008-06-08.22:56:17
fixed in r4572
History
Date User Action Args
2008-06-08 22:56:17pjenveysetstatus: open -> closed
nosy: + pjenvey
resolution: fixed
messages: + msg3259
2006-11-29 04:47:44cgrovescreate