@@ -1231,14 +1231,34 @@ static PyGetSetDef PyContextTokenType_getsetlist[] = {
12311231 {NULL }
12321232};
12331233
1234+ /*[clinic input]
1235+ _contextvars.Token.__enter__ as token_enter
1236+
1237+ Enter into Token context manager.
1238+ [clinic start generated code]*/
1239+
12341240static PyObject *
1235- token_enter (PyContextToken * self , PyObject * args )
1241+ token_enter_impl (PyContextToken * self )
1242+ /*[clinic end generated code: output=9af4d2054e93fb75 input=41a3d6c4195fd47a]*/
12361243{
12371244 return Py_NewRef (self );
12381245}
12391246
1247+ /*[clinic input]
1248+ _contextvars.Token.__exit__ as token_exit
1249+
1250+ type: object
1251+ val: object
1252+ tb: object
1253+ /
1254+
1255+ Exit from Token context manager, restore the linked ContextVar.
1256+ [clinic start generated code]*/
1257+
12401258static PyObject *
1241- token_exit (PyContextToken * self , PyObject * args )
1259+ token_exit_impl (PyContextToken * self , PyObject * type , PyObject * val ,
1260+ PyObject * tb )
1261+ /*[clinic end generated code: output=3e6a1c95d3da703a input=7f117445f0ccd92e]*/
12421262{
12431263 int ret = PyContextVar_Reset ((PyObject * )self -> tok_var , (PyObject * )self );
12441264 if (ret < 0 ) {
@@ -1250,10 +1270,8 @@ token_exit(PyContextToken *self, PyObject *args)
12501270static PyMethodDef PyContextTokenType_methods [] = {
12511271 {"__class_getitem__" , Py_GenericAlias ,
12521272 METH_O |METH_CLASS , PyDoc_STR ("See PEP 585" )},
1253-
1254- {"__enter__" , (PyCFunction )token_enter , METH_NOARGS , NULL },
1255- {"__exit__" , (PyCFunction )token_exit , METH_VARARGS , NULL },
1256-
1273+ BLOB_ENTER_METHODDEF
1274+ BLOB_EXIT_METHODDEF
12571275 {NULL }
12581276};
12591277
0 commit comments