From: Hugo Date: Thu, 14 Mar 2019 12:41:42 +0000 (+0200) Subject: Fix PendingDeprecationWarning: Task.all_tasks() is deprecated, use asyncio.all_tasks... X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/d00eac9944acdafe2fb61a61c7e763c6502e89d5?ds=sidebyside Fix PendingDeprecationWarning: Task.all_tasks() is deprecated, use asyncio.all_tasks() instead (#741) --- diff --git a/black.py b/black.py index 200e15f..db1b2b6 100644 --- a/black.py +++ b/black.py @@ -3423,8 +3423,12 @@ def cancel(tasks: Iterable[asyncio.Task]) -> None: def shutdown(loop: BaseEventLoop) -> None: """Cancel all pending tasks on `loop`, wait for them, and close the loop.""" try: + if sys.version_info[:2] >= (3, 7): + all_tasks = asyncio.all_tasks + else: + all_tasks = asyncio.Task.all_tasks # This part is borrowed from asyncio/runners.py in Python 3.7b2. - to_cancel = [task for task in asyncio.Task.all_tasks(loop) if not task.done()] + to_cancel = [task for task in all_tasks(loop) if not task.done()] if not to_cancel: return