mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
gh-104770: Let generator.close() return value (#104771)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
parent
50fce89d12
commit
d56c933992
4 changed files with 105 additions and 9 deletions
|
@ -408,11 +408,16 @@ gen_close(PyGenObject *gen, PyObject *args)
|
|||
PyErr_SetString(PyExc_RuntimeError, msg);
|
||||
return NULL;
|
||||
}
|
||||
if (PyErr_ExceptionMatches(PyExc_StopIteration)
|
||||
|| PyErr_ExceptionMatches(PyExc_GeneratorExit)) {
|
||||
PyErr_Clear(); /* ignore these errors */
|
||||
assert(PyErr_Occurred());
|
||||
if (PyErr_ExceptionMatches(PyExc_GeneratorExit)) {
|
||||
PyErr_Clear(); /* ignore this error */
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
/* if the generator returned a value while closing, StopIteration was
|
||||
* raised in gen_send_ex() above; retrieve and return the value here */
|
||||
if (_PyGen_FetchStopIterationValue(&retval) == 0) {
|
||||
return retval;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue