Skip to content

Commit 0968bb6

Browse files
committed
Removed asyncio.Task.current_task() and asyncio.Task.all_tasks()
1 parent 714217f commit 0968bb6

File tree

4 files changed

+3
-98
lines changed

4 files changed

+3
-98
lines changed

Doc/library/asyncio-task.rst

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -962,31 +962,6 @@ Task Object
962962

963963
.. versionadded:: 3.8
964964

965-
.. classmethod:: all_tasks(loop=None)
966-
967-
Return a set of all tasks for an event loop.
968-
969-
By default all tasks for the current event loop are returned.
970-
If *loop* is ``None``, the :func:`get_event_loop` function
971-
is used to get the current loop.
972-
973-
.. deprecated-removed:: 3.7 3.9
974-
975-
Do not call this as a task method. Use the :func:`asyncio.all_tasks`
976-
function instead.
977-
978-
.. classmethod:: current_task(loop=None)
979-
980-
Return the currently running task or ``None``.
981-
982-
If *loop* is ``None``, the :func:`get_event_loop` function
983-
is used to get the current loop.
984-
985-
.. deprecated-removed:: 3.7 3.9
986-
987-
Do not call this as a task method. Use the
988-
:func:`asyncio.current_task` function instead.
989-
990965

991966
.. _asyncio_generator_based_coro:
992967

Lib/asyncio/tasks.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -113,34 +113,6 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
113113
# status is still pending
114114
_log_destroy_pending = True
115115

116-
@classmethod
117-
def current_task(cls, loop=None):
118-
"""Return the currently running task in an event loop or None.
119-
120-
By default the current task for the current event loop is returned.
121-
122-
None is returned when called not in the context of a Task.
123-
"""
124-
warnings.warn("Task.current_task() is deprecated since Python 3.7, "
125-
"use asyncio.current_task() instead",
126-
DeprecationWarning,
127-
stacklevel=2)
128-
if loop is None:
129-
loop = events.get_event_loop()
130-
return current_task(loop)
131-
132-
@classmethod
133-
def all_tasks(cls, loop=None):
134-
"""Return a set of all tasks for an event loop.
135-
136-
By default all tasks for the current event loop are returned.
137-
"""
138-
warnings.warn("Task.all_tasks() is deprecated since Python 3.7, "
139-
"use asyncio.all_tasks() instead",
140-
DeprecationWarning,
141-
stacklevel=2)
142-
return _all_tasks_compat(loop)
143-
144116
def __init__(self, coro, *, loop=None, name=None):
145117
super().__init__(loop=loop)
146118
if self._source_traceback:

Lib/test/test_asyncio/test_tasks.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,32 +1943,6 @@ async def coro():
19431943
self.assertEqual(res, 'test')
19441944
self.assertIsNone(t2.result())
19451945

1946-
1947-
def test_current_task_deprecated(self):
1948-
Task = self.__class__.Task
1949-
1950-
with self.assertWarns(DeprecationWarning):
1951-
self.assertIsNone(Task.current_task(loop=self.loop))
1952-
1953-
async def coro(loop):
1954-
with self.assertWarns(DeprecationWarning):
1955-
self.assertIs(Task.current_task(loop=loop), task)
1956-
1957-
# See http://bugs.python.org/issue29271 for details:
1958-
asyncio.set_event_loop(loop)
1959-
try:
1960-
with self.assertWarns(DeprecationWarning):
1961-
self.assertIs(Task.current_task(None), task)
1962-
with self.assertWarns(DeprecationWarning):
1963-
self.assertIs(Task.current_task(), task)
1964-
finally:
1965-
asyncio.set_event_loop(None)
1966-
1967-
task = self.new_task(self.loop, coro(self.loop))
1968-
self.loop.run_until_complete(task)
1969-
with self.assertWarns(DeprecationWarning):
1970-
self.assertIsNone(Task.current_task(loop=self.loop))
1971-
19721946
def test_current_task(self):
19731947
self.assertIsNone(asyncio.current_task(loop=self.loop))
19741948

@@ -2305,16 +2279,6 @@ def foo():
23052279
self.assertIsInstance(exception, Exception)
23062280
self.assertEqual(exception.args, ("foo", ))
23072281

2308-
def test_all_tasks_deprecated(self):
2309-
Task = self.__class__.Task
2310-
2311-
async def coro():
2312-
with self.assertWarns(DeprecationWarning):
2313-
assert Task.all_tasks(self.loop) == {t}
2314-
2315-
t = self.new_task(self.loop, coro())
2316-
self.loop.run_until_complete(t)
2317-
23182282
def test_log_destroyed_pending_task(self):
23192283
Task = self.__class__.Task
23202284

@@ -2337,15 +2301,7 @@ def kill_me(loop):
23372301

23382302
self.assertEqual(asyncio.all_tasks(loop=self.loop), {task})
23392303

2340-
# See http://bugs.python.org/issue29271 for details:
2341-
asyncio.set_event_loop(self.loop)
2342-
try:
2343-
with self.assertWarns(DeprecationWarning):
2344-
self.assertEqual(Task.all_tasks(), {task})
2345-
with self.assertWarns(DeprecationWarning):
2346-
self.assertEqual(Task.all_tasks(None), {task})
2347-
finally:
2348-
asyncio.set_event_loop(None)
2304+
asyncio.set_event_loop(None)
23492305

23502306
# execute the task so it waits for future
23512307
self.loop._run_once()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Removed :meth:`asyncio.Task.current_task` and
2+
:meth:`asyncio.Task.all_tasks`. Patch contributed by Rémi Lapeyre.

0 commit comments

Comments
 (0)