diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-10-22 02:50:38 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-10-22 02:50:38 (GMT) |
commit | 97a57ec0487826b614aeeb198f396eac4f3ab401 (patch) | |
tree | 9e98cd6cea4bdfd7891dcc67ccb398761595cf7f /Objects/descrobject.c | |
parent | ff81cb812dac5c6f01006fd3d39b99bba6ffc263 (diff) | |
download | cpython-97a57ec0487826b614aeeb198f396eac4f3ab401.zip cpython-97a57ec0487826b614aeeb198f396eac4f3ab401.tar.gz cpython-97a57ec0487826b614aeeb198f396eac4f3ab401.tar.bz2 |
rewrite for style, clarify, and comments
Also, use the hasattr() like scheme of allowing BaseException exceptions through.
Diffstat (limited to 'Objects/descrobject.c')
-rw-r--r-- | Objects/descrobject.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/Objects/descrobject.c b/Objects/descrobject.c index cbc43ac..168ba74 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -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 ((doc == NULL || doc == Py_None) && get != NULL) { PyObject *get_doc = PyObject_GetAttrString(get, "__doc__"); - if (get_doc != NULL) { - /* get_doc already INCREF'd by GetAttr */ + if (get_doc) { 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); + } + else { + /* If this is a property subclass, put __doc__ + in dict of the subclass instance instead, + otherwise it gets shadowed by __doc__ in the + class's dict. */ + int err = PyObject_SetAttrString(self, "__doc__", get_doc); + Py_DECREF(get_doc); + if (err < 0) return -1; - } - Py_DECREF(get_doc); } prop->getter_doc = 1; - } else { + } + else if (PyErr_ExceptionMatches(PyExc_Exception)) { PyErr_Clear(); } + else { + return -1; + } } return 0; |