Skip to content

Commit e9116f3

Browse files
committed
GH-117714: replace athrow().close() and asend().close() stubs with implimentations
1 parent 3131a70 commit e9116f3

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

Objects/genobject.c

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,8 +1843,25 @@ async_gen_asend_throw(PyAsyncGenASend *o, PyObject *const *args, Py_ssize_t narg
18431843
static PyObject *
18441844
async_gen_asend_close(PyAsyncGenASend *o, PyObject *args)
18451845
{
1846-
o->ags_state = AWAITABLE_STATE_CLOSED;
1847-
Py_RETURN_NONE;
1846+
PyObject *result;
1847+
if (o->ags_state == AWAITABLE_STATE_CLOSED) {
1848+
Py_RETURN_NONE;
1849+
}
1850+
result = async_gen_asend_throw(o, PyExc_GeneratorExit, 1);
1851+
if (result == NULL) {
1852+
if (PyErr_ExceptionMatches(PyExc_StopIteration) ||
1853+
PyErr_ExceptionMatches(PyExc_StopAsyncIteration) ||
1854+
PyErr_ExceptionMatches(PyExc_GeneratorExit))
1855+
{
1856+
PyErr_Clear();
1857+
Py_RETURN_NONE;
1858+
}
1859+
return result;
1860+
} else {
1861+
Py_DECREF(result);
1862+
PyErr_SetString(PyExc_RuntimeError, "coroutine ignored GeneratorExit");
1863+
return NULL;
1864+
}
18481865
}
18491866

18501867
static void
@@ -2288,8 +2305,25 @@ async_gen_athrow_iternext(PyAsyncGenAThrow *o)
22882305
static PyObject *
22892306
async_gen_athrow_close(PyAsyncGenAThrow *o, PyObject *args)
22902307
{
2291-
o->agt_state = AWAITABLE_STATE_CLOSED;
2292-
Py_RETURN_NONE;
2308+
PyObject *result;
2309+
if (o->agt_state == AWAITABLE_STATE_CLOSED) {
2310+
Py_RETURN_NONE;
2311+
}
2312+
result = async_gen_athrow_throw(o, PyExc_GeneratorExit, 1);
2313+
if (result == NULL) {
2314+
if (PyErr_ExceptionMatches(PyExc_StopIteration) ||
2315+
PyErr_ExceptionMatches(PyExc_StopAsyncIteration) ||
2316+
PyErr_ExceptionMatches(PyExc_GeneratorExit))
2317+
{
2318+
PyErr_Clear();
2319+
Py_RETURN_NONE;
2320+
}
2321+
return result;
2322+
} else {
2323+
Py_DECREF(result);
2324+
PyErr_SetString(PyExc_RuntimeError, "coroutine ignored GeneratorExit");
2325+
return NULL;
2326+
}
22932327
}
22942328

22952329

0 commit comments

Comments
 (0)