rewrite for style, clarify, and comments

Also, use the hasattr() like scheme of allowing BaseException exceptions through.
This commit is contained in:
Benjamin Peterson 2009-10-22 02:50:38 +00:00
parent ff81cb812d
commit 97a57ec048
1 changed files with 15 additions and 12 deletions

View File

@ -1280,26 +1280,29 @@ property_init(PyObject *self, PyObject *args, PyObject *kwds)
/* if no docstring given and the getter has one, use that one */ /* if no docstring given and the getter has one, use that one */
if ((doc == NULL || doc == Py_None) && get != NULL) { if ((doc == NULL || doc == Py_None) && get != NULL) {
PyObject *get_doc = PyObject_GetAttrString(get, "__doc__"); PyObject *get_doc = PyObject_GetAttrString(get, "__doc__");
if (get_doc != NULL) { if (get_doc) {
/* get_doc already INCREF'd by GetAttr */
if (Py_TYPE(self) == &PyProperty_Type) { if (Py_TYPE(self) == &PyProperty_Type) {
Py_XDECREF(prop->prop_doc); Py_XDECREF(prop->prop_doc);
prop->prop_doc = get_doc; prop->prop_doc = get_doc;
} else { }
/* Put __doc__ in dict of the subclass instance instead, else {
otherwise it gets shadowed by class's __doc__. */ /* If this is a property subclass, put __doc__
if (PyObject_SetAttrString(self, "__doc__", get_doc) != 0) in dict of the subclass instance instead,
{ otherwise it gets shadowed by __doc__ in the
/* DECREF for props handled by _dealloc */ class's dict. */
Py_DECREF(get_doc); int err = PyObject_SetAttrString(self, "__doc__", get_doc);
Py_DECREF(get_doc);
if (err < 0)
return -1; return -1;
}
Py_DECREF(get_doc);
} }
prop->getter_doc = 1; prop->getter_doc = 1;
} else { }
else if (PyErr_ExceptionMatches(PyExc_Exception)) {
PyErr_Clear(); PyErr_Clear();
} }
else {
return -1;
}
} }
return 0; return 0;