summaryrefslogtreecommitdiffstats
path: root/Objects/genobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/genobject.c')
-rw-r--r--Objects/genobject.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 0a34c1f..7baffa7 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -352,13 +352,11 @@ gen_close_iter(PyObject *yf)
return -1;
}
else {
- PyObject *meth = _PyObject_GetAttrId(yf, &PyId_close);
- if (meth == NULL) {
- if (!PyErr_ExceptionMatches(PyExc_AttributeError))
- PyErr_WriteUnraisable(yf);
- PyErr_Clear();
+ PyObject *meth;
+ if (_PyObject_LookupAttrId(yf, &PyId_close, &meth) < 0) {
+ PyErr_WriteUnraisable(yf);
}
- else {
+ if (meth) {
retval = _PyObject_CallNoArg(meth);
Py_DECREF(meth);
if (retval == NULL)
@@ -471,13 +469,12 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
gen->gi_running = 0;
} else {
/* `yf` is an iterator or a coroutine-like object. */
- PyObject *meth = _PyObject_GetAttrId(yf, &PyId_throw);
+ PyObject *meth;
+ if (_PyObject_LookupAttrId(yf, &PyId_throw, &meth) < 0) {
+ Py_DECREF(yf);
+ return NULL;
+ }
if (meth == NULL) {
- if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
- Py_DECREF(yf);
- return NULL;
- }
- PyErr_Clear();
Py_DECREF(yf);
goto throw_here;
}