mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-37994: Fix silencing all errors if an attribute lookup fails. (GH-15630)
Only AttributeError should be silenced.
This commit is contained in:
parent
f02ea6225b
commit
41c57b3353
14 changed files with 134 additions and 127 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue