mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Merged revisions 72299 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r72299 | r.david.murray | 2009-05-04 18:16:24 -0400 (Mon, 04 May 2009) | 7 lines 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. ........
This commit is contained in:
parent
e04b627a11
commit
b18500d39d
3 changed files with 142 additions and 17 deletions
|
@ -1246,25 +1246,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;
|
||||
}
|
||||
|
||||
|
@ -1301,8 +1295,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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue