diff options
Diffstat (limited to 'Objects/descrobject.c')
-rw-r--r-- | Objects/descrobject.c | 39 |
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(); |