summaryrefslogtreecommitdiffstats
path: root/Objects/descrobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-09-01 09:03:39 (GMT)
committerGitHub <noreply@github.com>2019-09-01 09:03:39 (GMT)
commit41c57b335330ff48af098d47e379e0f9ba09d233 (patch)
tree15cdef099182eddb04b2276dc51375b8faf28278 /Objects/descrobject.c
parentf02ea6225bc3b71bd5fe66224d199a6e3e23b14d (diff)
downloadcpython-41c57b335330ff48af098d47e379e0f9ba09d233.zip
cpython-41c57b335330ff48af098d47e379e0f9ba09d233.tar.gz
cpython-41c57b335330ff48af098d47e379e0f9ba09d233.tar.bz2
bpo-37994: Fix silencing all errors if an attribute lookup fails. (GH-15630)
Only AttributeError should be silenced.
Diffstat (limited to 'Objects/descrobject.c')
-rw-r--r--Objects/descrobject.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 9e1b281..c50fe00 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -1616,29 +1616,25 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset,
/* if no docstring given and the getter has one, use that one */
if ((doc == NULL || doc == Py_None) && fget != NULL) {
_Py_IDENTIFIER(__doc__);
- PyObject *get_doc = _PyObject_GetAttrId(fget, &PyId___doc__);
- if (get_doc) {
- if (Py_TYPE(self) == &PyProperty_Type) {
- Py_XSETREF(self->prop_doc, 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_SetAttrId((PyObject *)self, &PyId___doc__, get_doc);
- Py_DECREF(get_doc);
- if (err < 0)
- return -1;
- }
- self->getter_doc = 1;
+ PyObject *get_doc;
+ int rc = _PyObject_LookupAttrId(fget, &PyId___doc__, &get_doc);
+ if (rc <= 0) {
+ return rc;
}
- else if (PyErr_ExceptionMatches(PyExc_Exception)) {
- PyErr_Clear();
+ if (Py_TYPE(self) == &PyProperty_Type) {
+ Py_XSETREF(self->prop_doc, get_doc);
}
else {
- return -1;
+ /* 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_SetAttrId((PyObject *)self, &PyId___doc__, get_doc);
+ Py_DECREF(get_doc);
+ if (err < 0)
+ return -1;
}
+ self->getter_doc = 1;
}
return 0;