diff options
author | RĂ©mi Lapeyre <remi.lapeyre@lenstra.fr> | 2020-07-02 03:41:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-02 03:41:21 (GMT) |
commit | 004e64e8059fe68a72890314673282f2e60d5ce1 (patch) | |
tree | 02729d1a0324f5ccfbdea2d667cc2ec348c5a156 /Lib | |
parent | 666ecfb0957a2fa0df5e2bd03804195de74bdfbf (diff) | |
download | cpython-004e64e8059fe68a72890314673282f2e60d5ce1.zip cpython-004e64e8059fe68a72890314673282f2e60d5ce1.tar.gz cpython-004e64e8059fe68a72890314673282f2e60d5ce1.tar.bz2 |
bpo-40967: Remove deprecated asyncio.Task.current_task() and asyncio.Task.all_tasks() (GH-20874)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/asyncio/tasks.py | 28 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_tasks.py | 48 |
2 files changed, 1 insertions, 75 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 21b98b6..5e0692e 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -113,34 +113,6 @@ class Task(futures._PyFuture): # Inherit Python Task implementation # status is still pending _log_destroy_pending = True - @classmethod - def current_task(cls, loop=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. - """ - warnings.warn("Task.current_task() is deprecated since Python 3.7, " - "use asyncio.current_task() instead", - DeprecationWarning, - stacklevel=2) - if loop is None: - loop = events.get_event_loop() - return current_task(loop) - - @classmethod - def all_tasks(cls, loop=None): - """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=2) - return _all_tasks_compat(loop) - def __init__(self, coro, *, loop=None, name=None): super().__init__(loop=loop) if self._source_traceback: diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 3734013..f9db066 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -1943,32 +1943,6 @@ class BaseTaskTests: self.assertEqual(res, 'test') self.assertIsNone(t2.result()) - - def test_current_task_deprecated(self): - Task = self.__class__.Task - - with self.assertWarns(DeprecationWarning): - self.assertIsNone(Task.current_task(loop=self.loop)) - - async def coro(loop): - with self.assertWarns(DeprecationWarning): - self.assertIs(Task.current_task(loop=loop), 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 = self.new_task(self.loop, coro(self.loop)) - self.loop.run_until_complete(task) - with self.assertWarns(DeprecationWarning): - self.assertIsNone(Task.current_task(loop=self.loop)) - def test_current_task(self): self.assertIsNone(asyncio.current_task(loop=self.loop)) @@ -2305,16 +2279,6 @@ class BaseTaskTests: self.assertIsInstance(exception, Exception) self.assertEqual(exception.args, ("foo", )) - def test_all_tasks_deprecated(self): - Task = self.__class__.Task - - async def coro(): - with self.assertWarns(DeprecationWarning): - assert Task.all_tasks(self.loop) == {t} - - t = self.new_task(self.loop, coro()) - self.loop.run_until_complete(t) - def test_log_destroyed_pending_task(self): Task = self.__class__.Task @@ -2337,15 +2301,7 @@ class BaseTaskTests: self.assertEqual(asyncio.all_tasks(loop=self.loop), {task}) - # 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) # execute the task so it waits for future self.loop._run_once() @@ -3043,8 +2999,6 @@ class BaseTaskIntrospectionTests: 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) def test__enter_task(self): |