diff options
Diffstat (limited to 'Modules/_testmultiphase.c')
-rw-r--r-- | Modules/_testmultiphase.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/_testmultiphase.c b/Modules/_testmultiphase.c index c6dfc2f..db5bb7d 100644 --- a/Modules/_testmultiphase.c +++ b/Modules/_testmultiphase.c @@ -53,11 +53,14 @@ static PyObject * Example_getattro(ExampleObject *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); } @@ -72,7 +75,7 @@ Example_setattr(ExampleObject *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 Example attribute"); return rv; |