diff options
author | R. David Murray <rdmurray@bitdance.com> | 2009-05-04 22:59:07 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2009-05-04 22:59:07 (GMT) |
commit | b18500d39d791c879e9904ebac293402b4a7cd34 (patch) | |
tree | 109aad772fed30511f12977cc4b10b9b3fd56722 /Objects/descrobject.c | |
parent | e04b627a116b4fed8fd76f9376ef53592c49d183 (diff) | |
download | cpython-b18500d39d791c879e9904ebac293402b4a7cd34.zip cpython-b18500d39d791c879e9904ebac293402b4a7cd34.tar.gz cpython-b18500d39d791c879e9904ebac293402b4a7cd34.tar.bz2 |
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.
........
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 cfd4b4f..9715238 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -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(); |