@@ -1117,13 +1117,12 @@ gen_iternext_callback(PyFrameObject *f, int exc, PyObject *result)
1117
1117
}
1118
1118
Py_CLEAR (result );
1119
1119
}
1120
- else if (!result ) {
1120
+ else if (!result && PyErr_ExceptionMatches ( PyExc_StopIteration ) ) {
1121
1121
/* Check for __future__ generator_stop and conditionally turn
1122
1122
* a leaking StopIteration into RuntimeError (with its cause
1123
1123
* set appropriately). */
1124
- if (((( PyCodeObject * )gen -> gi_code )-> co_flags &
1124
+ if (((PyCodeObject * )gen -> gi_code )-> co_flags &
1125
1125
(CO_FUTURE_GENERATOR_STOP | CO_COROUTINE | CO_ITERABLE_COROUTINE ))
1126
- && PyErr_ExceptionMatches (PyExc_StopIteration ))
1127
1126
{
1128
1127
PyObject * exc , * val , * val2 , * tb ;
1129
1128
PyErr_Fetch (& exc , & val , & tb );
@@ -1141,6 +1140,24 @@ gen_iternext_callback(PyFrameObject *f, int exc, PyObject *result)
1141
1140
Py_INCREF (val );
1142
1141
PyErr_Restore (exc , val2 , tb );
1143
1142
}
1143
+ else {
1144
+ PyObject * exc , * val , * tb ;
1145
+
1146
+ /* Pop the exception before issuing a warning. */
1147
+ PyErr_Fetch (& exc , & val , & tb );
1148
+
1149
+ if (PyErr_WarnFormat (PyExc_PendingDeprecationWarning , 1 ,
1150
+ "generator '%.50S' raised StopIteration" ,
1151
+ gen -> gi_qualname )) {
1152
+ /* Warning was converted to an error. */
1153
+ Py_XDECREF (exc );
1154
+ Py_XDECREF (val );
1155
+ Py_XDECREF (tb );
1156
+ }
1157
+ else {
1158
+ PyErr_Restore (exc , val , tb );
1159
+ }
1160
+ }
1144
1161
}
1145
1162
1146
1163
gen -> gi_running = 0 ;
0 commit comments