summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2017-12-25 15:48:15 (GMT)
committerGitHub <noreply@github.com>2017-12-25 15:48:15 (GMT)
commit0cf16f9ea014b17d398ee3971d4976c698533318 (patch)
treec0a2ec1cc06a2519ea5b8a254de844ec1afb3955 /Modules
parent3dfbaf51f0d90646e0414ddbd3b513ee8e5ffe9b (diff)
downloadcpython-0cf16f9ea014b17d398ee3971d4976c698533318.zip
cpython-0cf16f9ea014b17d398ee3971d4976c698533318.tar.gz
cpython-0cf16f9ea014b17d398ee3971d4976c698533318.tar.bz2
bpo-32363: Disable Task.set_exception() and Task.set_result() (#4923)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_asynciomodule.c51
-rw-r--r--Modules/clinic/_asynciomodule.c.h20
2 files changed, 60 insertions, 11 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index f70e345..f8165ab 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -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);
diff --git a/Modules/clinic/_asynciomodule.c.h b/Modules/clinic/_asynciomodule.c.h
index 6a35434..f2e0f40 100644
--- a/Modules/clinic/_asynciomodule.c.h
+++ b/Modules/clinic/_asynciomodule.c.h
@@ -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]*/