To: python-checkins@python.org Subject: bpo-40967: Remove deprecated asyncio.Task.current_task() and asyncio.Task.all_tasks() (GH-20874) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 https://github.com/python/cpython/commit/004e64e8059fe68a72890314673282f2e60... 5ce1 commit: 004e64e8059fe68a72890314673282f2e60d5ce1 branch: master author: R=C3=A9mi Lapeyre <remi.lapeyre@lenstra.fr> committer: GitHub <noreply@github.com> date: 2020-07-01T20:41:21-07:00 summary: bpo-40967: Remove deprecated asyncio.Task.current_task() and asyncio.Task.all= _tasks() (GH-20874) files: A Misc/NEWS.d/next/Library/2020-06-15-00-13-57.bpo-40967._dx3OO.rst M Doc/library/asyncio-task.rst M Doc/whatsnew/3.9.rst M Lib/asyncio/tasks.py M Lib/test/test_asyncio/test_tasks.py M Modules/_asynciomodule.c M Modules/clinic/_asynciomodule.c.h diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst index 21824ca537f77..bac99b7950444 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -962,31 +962,6 @@ Task Object =20 .. versionadded:: 3.8 =20 - .. classmethod:: all_tasks(loop=3DNone) - - Return a set of all tasks for an event loop. - - By default all tasks for the current event loop are returned. - If *loop* is ``None``, the :func:`get_event_loop` function - is used to get the current loop. - - .. deprecated-removed:: 3.7 3.9 - - Do not call this as a task method. Use the :func:`asyncio.all_tasks` - function instead. - - .. classmethod:: current_task(loop=3DNone) - - Return the currently running task or ``None``. - - If *loop* is ``None``, the :func:`get_event_loop` function - is used to get the current loop. - - .. deprecated-removed:: 3.7 3.9 - - Do not call this as a task method. Use the - :func:`asyncio.current_task` function instead. - =20 .. _asyncio_generator_based_coro: =20 diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index 15fca8fa9d4c9..165ce69e59e1d 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -878,6 +878,11 @@ Removed deprecated since 2006, and only returning ``False`` when it's called. (Contributed by Batuhan Taskaya in :issue:`40208`) =20 +* The :meth:`asyncio.Task.current_task` and :meth:`asyncio.Task.all_tasks` h= ave + have been removed. They were deprecated since Python 3.7 and you can use + :func:`asyncio.current_task` and :func:`asyncio.all_tasks` instead. + (Contributed by R=C3=A9mi Lapeyre in :issue:`40967`) + =20 Porting to Python 3.9 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 21b98b6647bd9..5e0692ef7778a 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -113,34 +113,6 @@ class Task(futures._PyFuture): # Inherit Python Task im= plementation # status is still pending _log_destroy_pending =3D True =20 - @classmethod - def current_task(cls, loop=3DNone): - """Return the currently running task in an event loop or None. - - By default the current task for the current event loop is returned. - - None is returned when called not in the context of a Task. - """ - warnings.warn("Task.current_task() is deprecated since Python 3.7, " - "use asyncio.current_task() instead", - DeprecationWarning, - stacklevel=3D2) - if loop is None: - loop =3D events.get_event_loop() - return current_task(loop) - - @classmethod - def all_tasks(cls, loop=3DNone): - """Return a set of all tasks for an event loop. - - By default all tasks for the current event loop are returned. - """ - warnings.warn("Task.all_tasks() is deprecated since Python 3.7, " - "use asyncio.all_tasks() instead", - DeprecationWarning, - stacklevel=3D2) - return _all_tasks_compat(loop) - def __init__(self, coro, *, loop=3DNone, name=3DNone): super().__init__(loop=3Dloop) if self._source_traceback: diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test= _tasks.py index 3734013fad989..f9db066ce8983 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -1943,32 +1943,6 @@ async def coro(): self.assertEqual(res, 'test') self.assertIsNone(t2.result()) =20 - - def test_current_task_deprecated(self): - Task =3D self.__class__.Task - - with self.assertWarns(DeprecationWarning): - self.assertIsNone(Task.current_task(loop=3Dself.loop)) - - async def coro(loop): - with self.assertWarns(DeprecationWarning): - self.assertIs(Task.current_task(loop=3Dloop), task) - - # See http://bugs.python.org/issue29271 for details: - asyncio.set_event_loop(loop) - try: - with self.assertWarns(DeprecationWarning): - self.assertIs(Task.current_task(None), task) - with self.assertWarns(DeprecationWarning): - self.assertIs(Task.current_task(), task) - finally: - asyncio.set_event_loop(None) - - task =3D self.new_task(self.loop, coro(self.loop)) - self.loop.run_until_complete(task) - with self.assertWarns(DeprecationWarning): - self.assertIsNone(Task.current_task(loop=3Dself.loop)) - def test_current_task(self): self.assertIsNone(asyncio.current_task(loop=3Dself.loop)) =20 @@ -2305,16 +2279,6 @@ def foo(): self.assertIsInstance(exception, Exception) self.assertEqual(exception.args, ("foo", )) =20 - def test_all_tasks_deprecated(self): - Task =3D self.__class__.Task - - async def coro(): - with self.assertWarns(DeprecationWarning): - assert Task.all_tasks(self.loop) =3D=3D {t} - - t =3D self.new_task(self.loop, coro()) - self.loop.run_until_complete(t) - def test_log_destroyed_pending_task(self): Task =3D self.__class__.Task =20 @@ -2337,15 +2301,7 @@ def kill_me(loop): =20 self.assertEqual(asyncio.all_tasks(loop=3Dself.loop), {task}) =20 - # See http://bugs.python.org/issue29271 for details: - asyncio.set_event_loop(self.loop) - try: - with self.assertWarns(DeprecationWarning): - self.assertEqual(Task.all_tasks(), {task}) - with self.assertWarns(DeprecationWarning): - self.assertEqual(Task.all_tasks(None), {task}) - finally: - asyncio.set_event_loop(None) + asyncio.set_event_loop(None) =20 # execute the task so it waits for future self.loop._run_once() @@ -3043,8 +2999,6 @@ def done(self): self.assertEqual(asyncio.all_tasks(loop), set()) self._register_task(task) self.assertEqual(asyncio.all_tasks(loop), set()) - with self.assertWarns(DeprecationWarning): - self.assertEqual(asyncio.Task.all_tasks(loop), {task}) self._unregister_task(task) =20 def test__enter_task(self): diff --git a/Misc/NEWS.d/next/Library/2020-06-15-00-13-57.bpo-40967._dx3OO.rs= t b/Misc/NEWS.d/next/Library/2020-06-15-00-13-57.bpo-40967._dx3OO.rst new file mode 100644 index 0000000000000..4694d991babd7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-15-00-13-57.bpo-40967._dx3OO.rst @@ -0,0 +1,2 @@ +Removed :meth:`asyncio.Task.current_task` and +:meth:`asyncio.Task.all_tasks`. Patch contributed by R=C3=A9mi Lapeyre. diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 0454f9c6824bf..b378742648b2a 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -13,10 +13,8 @@ module _asyncio _Py_IDENTIFIER(__asyncio_running_event_loop__); _Py_IDENTIFIER(_asyncio_future_blocking); _Py_IDENTIFIER(add_done_callback); -_Py_IDENTIFIER(_all_tasks_compat); _Py_IDENTIFIER(call_soon); _Py_IDENTIFIER(cancel); -_Py_IDENTIFIER(current_task); _Py_IDENTIFIER(get_event_loop); _Py_IDENTIFIER(send); _Py_IDENTIFIER(throw); @@ -2182,91 +2180,6 @@ TaskObj_get_fut_waiter(TaskObj *task, void *Py_UNUSED(= ignored)) Py_RETURN_NONE; } =20 -/*[clinic input] -@classmethod -_asyncio.Task.current_task - - loop: object =3D None - -Return the currently running task in an event loop or None. - -By default the current task for the current event loop is returned. - -None is returned when called not in the context of a Task. -[clinic start generated code]*/ - -static PyObject * -_asyncio_Task_current_task_impl(PyTypeObject *type, PyObject *loop) -/*[clinic end generated code: output=3D99fbe7332c516e03 input=3Dcd14770c5b79= c7eb]*/ -{ - PyObject *ret; - PyObject *current_task_func; - - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Task.current_task() is deprecated, " \ - "use asyncio.current_task() instead", - 1) < 0) { - return NULL; - } - - current_task_func =3D _PyObject_GetAttrId(asyncio_mod, &PyId_current_tas= k); - if (current_task_func =3D=3D NULL) { - return NULL; - } - - if (loop =3D=3D Py_None) { - loop =3D get_event_loop(); - if (loop =3D=3D NULL) { - Py_DECREF(current_task_func); - return NULL; - } - ret =3D PyObject_CallOneArg(current_task_func, loop); - Py_DECREF(current_task_func); - Py_DECREF(loop); - return ret; - } - else { - ret =3D PyObject_CallOneArg(current_task_func, loop); - Py_DECREF(current_task_func); - return ret; - } -} - -/*[clinic input] -@classmethod -_asyncio.Task.all_tasks - - loop: object =3D None - -Return a set of all tasks for an event loop. - -By default all tasks for the current event loop are returned. -[clinic start generated code]*/ - -static PyObject * -_asyncio_Task_all_tasks_impl(PyTypeObject *type, PyObject *loop) -/*[clinic end generated code: output=3D11f9b20749ccca5d input=3D497f80bc9ce7= 26b5]*/ -{ - PyObject *res; - PyObject *all_tasks_func; - - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Task.all_tasks() is deprecated, " \ - "use asyncio.all_tasks() instead", - 1) < 0) { - return NULL; - } - - all_tasks_func =3D _PyObject_GetAttrId(asyncio_mod, &PyId__all_tasks_com= pat); - if (all_tasks_func =3D=3D NULL) { - return NULL; - } - - res =3D PyObject_CallOneArg(all_tasks_func, loop); - Py_DECREF(all_tasks_func); - return res; -} - /*[clinic input] _asyncio.Task._make_cancelled_error =20 @@ -2587,8 +2500,6 @@ static PyMethodDef TaskType_methods[] =3D { _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 _ASYNCIO_TASK_GET_STACK_METHODDEF _ASYNCIO_TASK_PRINT_STACK_METHODDEF diff --git a/Modules/clinic/_asynciomodule.c.h b/Modules/clinic/_asynciomodul= e.c.h index d3e59a4bc7822..a071efc1e2be3 100644 --- a/Modules/clinic/_asynciomodule.c.h +++ b/Modules/clinic/_asynciomodule.c.h @@ -355,86 +355,6 @@ _asyncio_Task___init__(PyObject *self, PyObject *args, P= yObject *kwargs) return return_value; } =20 -PyDoc_STRVAR(_asyncio_Task_current_task__doc__, -"current_task($type, /, loop=3DNone)\n" -"--\n" -"\n" -"Return the currently running task in an event loop or None.\n" -"\n" -"By default the current task for the current event loop is returned.\n" -"\n" -"None is returned when called not in the context of a Task."); - -#define _ASYNCIO_TASK_CURRENT_TASK_METHODDEF \ - {"current_task", (PyCFunction)(void(*)(void))_asyncio_Task_current_task,= METH_FASTCALL|METH_KEYWORDS|METH_CLASS, _asyncio_Task_current_task__doc__}, - -static PyObject * -_asyncio_Task_current_task_impl(PyTypeObject *type, PyObject *loop); - -static PyObject * -_asyncio_Task_current_task(PyTypeObject *type, PyObject *const *args, Py_ssi= ze_t nargs, PyObject *kwnames) -{ - PyObject *return_value =3D NULL; - static const char * const _keywords[] =3D {"loop", NULL}; - static _PyArg_Parser _parser =3D {NULL, _keywords, "current_task", 0}; - PyObject *argsbuf[1]; - Py_ssize_t noptargs =3D nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0= ) - 0; - PyObject *loop =3D Py_None; - - args =3D _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, = 1, 0, argsbuf); - if (!args) { - goto exit; - } - if (!noptargs) { - goto skip_optional_pos; - } - loop =3D args[0]; -skip_optional_pos: - return_value =3D _asyncio_Task_current_task_impl(type, loop); - -exit: - return return_value; -} - -PyDoc_STRVAR(_asyncio_Task_all_tasks__doc__, -"all_tasks($type, /, loop=3DNone)\n" -"--\n" -"\n" -"Return a set of all tasks for an event loop.\n" -"\n" -"By default all tasks for the current event loop are returned."); - -#define _ASYNCIO_TASK_ALL_TASKS_METHODDEF \ - {"all_tasks", (PyCFunction)(void(*)(void))_asyncio_Task_all_tasks, METH_= FASTCALL|METH_KEYWORDS|METH_CLASS, _asyncio_Task_all_tasks__doc__}, - -static PyObject * -_asyncio_Task_all_tasks_impl(PyTypeObject *type, PyObject *loop); - -static PyObject * -_asyncio_Task_all_tasks(PyTypeObject *type, PyObject *const *args, Py_ssize_= t nargs, PyObject *kwnames) -{ - PyObject *return_value =3D NULL; - static const char * const _keywords[] =3D {"loop", NULL}; - static _PyArg_Parser _parser =3D {NULL, _keywords, "all_tasks", 0}; - PyObject *argsbuf[1]; - Py_ssize_t noptargs =3D nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0= ) - 0; - PyObject *loop =3D Py_None; - - args =3D _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, = 1, 0, argsbuf); - if (!args) { - goto exit; - } - if (!noptargs) { - goto skip_optional_pos; - } - loop =3D args[0]; -skip_optional_pos: - return_value =3D _asyncio_Task_all_tasks_impl(type, loop); - -exit: - return return_value; -} - PyDoc_STRVAR(_asyncio_Task__make_cancelled_error__doc__, "_make_cancelled_error($self, /)\n" "--\n" @@ -912,4 +832,4 @@ _asyncio__leave_task(PyObject *module, PyObject *const *a= rgs, Py_ssize_t nargs, exit: return return_value; } -/*[clinic end generated code: output=3D0e5c1eb8b692977b input=3Da9049054013a= 1b77]*/ +/*[clinic end generated code: output=3Dd0fc522bcbff9d61 input=3Da9049054013a= 1b77]*/
participants (1)
-
Rémi Lapeyre