@@ -248,59 +248,17 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
248248 Py_CLEAR (result );
249249 }
250250 else if (!result && PyErr_ExceptionMatches (PyExc_StopIteration )) {
251- /* Check for __future__ generator_stop and conditionally turn
252- * a leaking StopIteration into RuntimeError (with its cause
253- * set appropriately). */
254-
255- const int check_stop_iter_error_flags = CO_FUTURE_GENERATOR_STOP |
256- CO_COROUTINE |
257- CO_ITERABLE_COROUTINE |
258- CO_ASYNC_GENERATOR ;
259-
260- if (gen -> gi_code != NULL &&
261- ((PyCodeObject * )gen -> gi_code )-> co_flags &
262- check_stop_iter_error_flags )
263- {
264- /* `gen` is either:
265- * a generator with CO_FUTURE_GENERATOR_STOP flag;
266- * a coroutine;
267- * a generator with CO_ITERABLE_COROUTINE flag
268- (decorated with types.coroutine decorator);
269- * an async generator.
270- */
271- const char * msg = "generator raised StopIteration" ;
272- if (PyCoro_CheckExact (gen )) {
273- msg = "coroutine raised StopIteration" ;
274- }
275- else if PyAsyncGen_CheckExact (gen ) {
276- msg = "async generator raised StopIteration" ;
277- }
278- _PyErr_FormatFromCause (PyExc_RuntimeError , "%s" , msg );
251+ const char * msg = "generator raised StopIteration" ;
252+ if (PyCoro_CheckExact (gen )) {
253+ msg = "coroutine raised StopIteration" ;
279254 }
280- else {
281- /* `gen` is an ordinary generator without
282- CO_FUTURE_GENERATOR_STOP flag.
283- */
284-
285- PyObject * exc , * val , * tb ;
286-
287- /* Pop the exception before issuing a warning. */
288- PyErr_Fetch (& exc , & val , & tb );
289-
290- if (PyErr_WarnFormat (PyExc_DeprecationWarning , 1 ,
291- "generator '%.50S' raised StopIteration" ,
292- gen -> gi_qualname )) {
293- /* Warning was converted to an error. */
294- Py_XDECREF (exc );
295- Py_XDECREF (val );
296- Py_XDECREF (tb );
297- }
298- else {
299- PyErr_Restore (exc , val , tb );
300- }
255+ else if PyAsyncGen_CheckExact (gen ) {
256+ msg = "async generator raised StopIteration" ;
301257 }
258+ _PyErr_FormatFromCause (PyExc_RuntimeError , "%s" , msg );
259+
302260 }
303- else if (PyAsyncGen_CheckExact ( gen ) && ! result &&
261+ else if (! result && PyAsyncGen_CheckExact ( gen ) &&
304262 PyErr_ExceptionMatches (PyExc_StopAsyncIteration ))
305263 {
306264 /* code in `gen` raised a StopAsyncIteration error:
0 commit comments