@@ -933,13 +933,32 @@ frame_tp_clear(PyFrameObject *f)
933
933
}
934
934
935
935
static PyObject *
936
- frame_clear (PyFrameObject * f , PyObject * Py_UNUSED ( ignored ) )
936
+ frame_clear (PyFrameObject * f , PyObject * args , PyObject * kwds )
937
937
{
938
+ bool raise_if_suspended = false;
939
+ PyObject * v = NULL ;
940
+ if (!PyArg_UnpackTuple (args , "clear" , 0 , 1 , & v )) {
941
+ return NULL ;
942
+ }
943
+ if (v != NULL && PyObject_IsTrue (v )) {
944
+ raise_if_suspended = true;
945
+ }
946
+
938
947
if (f -> f_frame -> owner == FRAME_OWNED_BY_GENERATOR ) {
939
948
PyGenObject * gen = _PyFrame_GetGenerator (f -> f_frame );
940
949
if (gen -> gi_frame_state == FRAME_EXECUTING ) {
941
950
goto running ;
942
951
}
952
+ if (FRAME_STATE_SUSPENDED (gen -> gi_frame_state )) {
953
+ if (raise_if_suspended ) {
954
+ PyErr_SetString (PyExc_RuntimeError , "cannot clear a suspended frame" );
955
+ return NULL ;
956
+ }
957
+ if (PyErr_WarnEx (PyExc_DeprecationWarning ,
958
+ "clearing a suspended frame is deprecated" , 1 ) < 0 ) {
959
+ return NULL ;
960
+ }
961
+ }
943
962
_PyGen_Finalize ((PyObject * )gen );
944
963
}
945
964
else if (f -> f_frame -> owner == FRAME_OWNED_BY_THREAD ) {
@@ -983,7 +1002,7 @@ frame_repr(PyFrameObject *f)
983
1002
}
984
1003
985
1004
static PyMethodDef frame_methods [] = {
986
- {"clear" , (PyCFunction )frame_clear , METH_NOARGS ,
1005
+ {"clear" , (PyCFunction )frame_clear , METH_VARARGS ,
987
1006
clear__doc__ },
988
1007
{"__sizeof__" , (PyCFunction )frame_sizeof , METH_NOARGS ,
989
1008
sizeof__doc__ },
0 commit comments