mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
bpo-32363: Disable Task.set_exception() and Task.set_result() (#4923)
This commit is contained in:
parent
3dfbaf51f0
commit
0cf16f9ea0
7 changed files with 158 additions and 44 deletions
|
@ -779,7 +779,7 @@ _asyncio_Future_exception_impl(FutureObj *self)
|
|||
/*[clinic input]
|
||||
_asyncio.Future.set_result
|
||||
|
||||
res: object
|
||||
result: object
|
||||
/
|
||||
|
||||
Mark the future done and set its result.
|
||||
|
@ -789,11 +789,11 @@ InvalidStateError.
|
|||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_asyncio_Future_set_result(FutureObj *self, PyObject *res)
|
||||
/*[clinic end generated code: output=a620abfc2796bfb6 input=5b9dc180f1baa56d]*/
|
||||
_asyncio_Future_set_result(FutureObj *self, PyObject *result)
|
||||
/*[clinic end generated code: output=1ec2e6bcccd6f2ce input=8b75172c2a7b05f1]*/
|
||||
{
|
||||
ENSURE_FUTURE_ALIVE(self)
|
||||
return future_set_result(self, res);
|
||||
return future_set_result(self, result);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
|
@ -1468,8 +1468,8 @@ FutureIter_iternext(futureiterobject *it)
|
|||
Py_INCREF(fut);
|
||||
return (PyObject *)fut;
|
||||
}
|
||||
PyErr_SetString(PyExc_AssertionError,
|
||||
"yield from wasn't used with future");
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"await wasn't used with future");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -2232,6 +2232,39 @@ _asyncio_Task__wakeup_impl(TaskObj *self, PyObject *fut)
|
|||
return task_wakeup(self, fut);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_asyncio.Task.set_result
|
||||
|
||||
result: object
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_asyncio_Task_set_result(TaskObj *self, PyObject *result)
|
||||
/*[clinic end generated code: output=1dcae308bfcba318 input=9d1a00c07be41bab]*/
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"Task does not support set_result operation");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_asyncio.Task.set_exception
|
||||
|
||||
exception: object
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_asyncio_Task_set_exception(TaskObj *self, PyObject *exception)
|
||||
/*[clinic end generated code: output=bc377fc28067303d input=9a8f65c83dcf893a]*/
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"Task doed not support set_exception operation");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
TaskObj_finalize(TaskObj *task)
|
||||
{
|
||||
|
@ -2304,12 +2337,12 @@ static void TaskObj_dealloc(PyObject *); /* Needs Task_CheckExact */
|
|||
static PyMethodDef TaskType_methods[] = {
|
||||
_ASYNCIO_FUTURE_RESULT_METHODDEF
|
||||
_ASYNCIO_FUTURE_EXCEPTION_METHODDEF
|
||||
_ASYNCIO_FUTURE_SET_RESULT_METHODDEF
|
||||
_ASYNCIO_FUTURE_SET_EXCEPTION_METHODDEF
|
||||
_ASYNCIO_FUTURE_ADD_DONE_CALLBACK_METHODDEF
|
||||
_ASYNCIO_FUTURE_REMOVE_DONE_CALLBACK_METHODDEF
|
||||
_ASYNCIO_FUTURE_CANCELLED_METHODDEF
|
||||
_ASYNCIO_FUTURE_DONE_METHODDEF
|
||||
_ASYNCIO_TASK_SET_RESULT_METHODDEF
|
||||
_ASYNCIO_TASK_SET_EXCEPTION_METHODDEF
|
||||
_ASYNCIO_TASK_CURRENT_TASK_METHODDEF
|
||||
_ASYNCIO_TASK_ALL_TASKS_METHODDEF
|
||||
_ASYNCIO_TASK_CANCEL_METHODDEF
|
||||
|
@ -2461,7 +2494,7 @@ task_step_impl(TaskObj *task, PyObject *exc)
|
|||
PyObject *o;
|
||||
|
||||
if (task->task_state != STATE_PENDING) {
|
||||
PyErr_Format(PyExc_AssertionError,
|
||||
PyErr_Format(asyncio_InvalidStateError,
|
||||
"_step(): already done: %R %R",
|
||||
task,
|
||||
exc ? exc : Py_None);
|
||||
|
|
|
@ -86,7 +86,7 @@ _asyncio_Future_exception(FutureObj *self, PyObject *Py_UNUSED(ignored))
|
|||
}
|
||||
|
||||
PyDoc_STRVAR(_asyncio_Future_set_result__doc__,
|
||||
"set_result($self, res, /)\n"
|
||||
"set_result($self, result, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Mark the future done and set its result.\n"
|
||||
|
@ -536,6 +536,22 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_asyncio_Task_set_result__doc__,
|
||||
"set_result($self, result, /)\n"
|
||||
"--\n"
|
||||
"\n");
|
||||
|
||||
#define _ASYNCIO_TASK_SET_RESULT_METHODDEF \
|
||||
{"set_result", (PyCFunction)_asyncio_Task_set_result, METH_O, _asyncio_Task_set_result__doc__},
|
||||
|
||||
PyDoc_STRVAR(_asyncio_Task_set_exception__doc__,
|
||||
"set_exception($self, exception, /)\n"
|
||||
"--\n"
|
||||
"\n");
|
||||
|
||||
#define _ASYNCIO_TASK_SET_EXCEPTION_METHODDEF \
|
||||
{"set_exception", (PyCFunction)_asyncio_Task_set_exception, METH_O, _asyncio_Task_set_exception__doc__},
|
||||
|
||||
PyDoc_STRVAR(_asyncio__get_running_loop__doc__,
|
||||
"_get_running_loop($module, /)\n"
|
||||
"--\n"
|
||||
|
@ -747,4 +763,4 @@ _asyncio__leave_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs,
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=5d100b3d74f2a0f4 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=616e814431893dcc input=a9049054013a1b77]*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue