@@ -1735,6 +1735,10 @@ async_gen_unwrap_value(PyAsyncGenObject *gen, PyObject *result)
17351735static void
17361736async_gen_asend_dealloc (PyAsyncGenASend * o )
17371737{
1738+ if (PyObject_CallFinalizerFromDealloc ((PyObject * )o )) {
1739+ return ;
1740+ }
1741+
17381742 _PyObject_GC_UNTRACK ((PyObject * )o );
17391743 Py_CLEAR (o -> ags_gen );
17401744 Py_CLEAR (o -> ags_sendval );
@@ -1839,6 +1843,13 @@ async_gen_asend_close(PyAsyncGenASend *o, PyObject *args)
18391843 Py_RETURN_NONE ;
18401844}
18411845
1846+ static void
1847+ async_gen_asend_finalize (PyAsyncGenASend * o )
1848+ {
1849+ if (o -> ags_state == AWAITABLE_STATE_INIT ) {
1850+ _PyErr_WarnUnawaitedAgenMethod (o -> ags_gen , & _Py_ID (asend ));
1851+ }
1852+ }
18421853
18431854static PyMethodDef async_gen_asend_methods [] = {
18441855 {"send" , (PyCFunction )async_gen_asend_send , METH_O , send_doc },
@@ -1896,6 +1907,7 @@ PyTypeObject _PyAsyncGenASend_Type = {
18961907 0 , /* tp_init */
18971908 0 , /* tp_alloc */
18981909 0 , /* tp_new */
1910+ .tp_finalize = (destructor )async_gen_asend_finalize ,
18991911};
19001912
19011913
@@ -2053,6 +2065,10 @@ _PyAsyncGenValueWrapperNew(PyThreadState *tstate, PyObject *val)
20532065static void
20542066async_gen_athrow_dealloc (PyAsyncGenAThrow * o )
20552067{
2068+ if (PyObject_CallFinalizerFromDealloc ((PyObject * )o )) {
2069+ return ;
2070+ }
2071+
20562072 _PyObject_GC_UNTRACK ((PyObject * )o );
20572073 Py_CLEAR (o -> agt_gen );
20582074 Py_CLEAR (o -> agt_args );
@@ -2256,6 +2272,15 @@ async_gen_athrow_close(PyAsyncGenAThrow *o, PyObject *args)
22562272}
22572273
22582274
2275+ static void
2276+ async_gen_athrow_finalize (PyAsyncGenAThrow * o )
2277+ {
2278+ if (o -> agt_state == AWAITABLE_STATE_INIT ) {
2279+ PyObject * method = o -> agt_args ? & _Py_ID (athrow ) : & _Py_ID (aclose );
2280+ _PyErr_WarnUnawaitedAgenMethod (o -> agt_gen , method );
2281+ }
2282+ }
2283+
22592284static PyMethodDef async_gen_athrow_methods [] = {
22602285 {"send" , (PyCFunction )async_gen_athrow_send , METH_O , send_doc },
22612286 {"throw" , _PyCFunction_CAST (async_gen_athrow_throw ),
@@ -2313,6 +2338,7 @@ PyTypeObject _PyAsyncGenAThrow_Type = {
23132338 0 , /* tp_init */
23142339 0 , /* tp_alloc */
23152340 0 , /* tp_new */
2341+ .tp_finalize = (destructor )async_gen_athrow_finalize ,
23162342};
23172343
23182344
0 commit comments