mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)
This commit is contained in:
parent
a180b007d9
commit
a24107b04c
31 changed files with 538 additions and 242 deletions
|
@ -78,11 +78,14 @@ static PyObject *
|
|||
Xxo_getattro(XxoObject *self, PyObject *name)
|
||||
{
|
||||
if (self->x_attr != NULL) {
|
||||
PyObject *v = PyDict_GetItem(self->x_attr, name);
|
||||
PyObject *v = PyDict_GetItemWithError(self->x_attr, name);
|
||||
if (v != NULL) {
|
||||
Py_INCREF(v);
|
||||
return v;
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return PyObject_GenericGetAttr((PyObject *)self, name);
|
||||
}
|
||||
|
@ -97,7 +100,7 @@ Xxo_setattr(XxoObject *self, const char *name, PyObject *v)
|
|||
}
|
||||
if (v == NULL) {
|
||||
int rv = PyDict_DelItemString(self->x_attr, name);
|
||||
if (rv < 0)
|
||||
if (rv < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"delete non-existing Xxo attribute");
|
||||
return rv;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue