summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2009-05-04 22:16:24 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2009-05-04 22:16:24 (GMT)
commit7ba8e1cbfdd262f809038fa590c6004ac71b3ce8 (patch)
tree015d5f8f5efc7b5a15b254825910a5be11ae020e /Objects
parent97377bf56685282ac6e504f64e71794a7bdd80b6 (diff)
downloadcpython-7ba8e1cbfdd262f809038fa590c6004ac71b3ce8.zip
cpython-7ba8e1cbfdd262f809038fa590c6004ac71b3ce8.tar.gz
cpython-7ba8e1cbfdd262f809038fa590c6004ac71b3ce8.tar.bz2
Fix issue 5890: (property subclass shadows __doc__ string) by inserting
the __doc__ into the subclass instance __dict__. The fix refactors property_copy to call property_init in such a way that the __doc__ logic is re-executed correctly when getter_doc is 1, thus simplifying property_copy.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/descrobject.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 536e5a8..f6f5976 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -1233,25 +1233,19 @@ property_copy(PyObject *old, PyObject *get, PyObject *set, PyObject *del,
}
if (doc == NULL || doc == Py_None) {
Py_XDECREF(doc);
- doc = pold->prop_doc ? pold->prop_doc : Py_None;
+ if (pold->getter_doc && get != Py_None) {
+ /* make _init use __doc__ from getter */
+ doc = Py_None;
+ }
+ else {
+ doc = pold->prop_doc ? pold->prop_doc : Py_None;
+ }
}
-
+
new = PyObject_CallFunction(type, "OOOO", get, set, del, doc);
Py_DECREF(type);
if (new == NULL)
return NULL;
- pnew = (propertyobject *)new;
-
- if (pold->getter_doc && get != Py_None) {
- PyObject *get_doc = PyObject_GetAttrString(get, "__doc__");
- if (get_doc != NULL) {
- Py_XDECREF(pnew->prop_doc);
- pnew->prop_doc = get_doc; /* get_doc already INCREF'd by GetAttr */
- pnew->getter_doc = 1;
- } else {
- PyErr_Clear();
- }
- }
return new;
}
@@ -1288,8 +1282,21 @@ property_init(PyObject *self, PyObject *args, PyObject *kwds)
if ((doc == NULL || doc == Py_None) && get != NULL) {
PyObject *get_doc = PyObject_GetAttrString(get, "__doc__");
if (get_doc != NULL) {
- Py_XDECREF(prop->prop_doc);
- prop->prop_doc = get_doc; /* get_doc already INCREF'd by GetAttr */
+ /* get_doc already INCREF'd by GetAttr */
+ if (Py_TYPE(self)==&PyProperty_Type) {
+ Py_XDECREF(prop->prop_doc);
+ prop->prop_doc = get_doc;
+ } else {
+ /* Put __doc__ in dict of the subclass instance instead,
+ otherwise it gets shadowed by class's __doc__. */
+ if (PyObject_SetAttrString(self, "__doc__", get_doc) != 0)
+ {
+ /* DECREF for props handled by _dealloc */
+ Py_DECREF(get_doc);
+ return -1;
+ }
+ Py_DECREF(get_doc);
+ }
prop->getter_doc = 1;
} else {
PyErr_Clear();