From d00eac9944acdafe2fb61a61c7e763c6502e89d5 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 14 Mar 2019 14:41:42 +0200 Subject: [PATCH] Fix PendingDeprecationWarning: Task.all_tasks() is deprecated, use asyncio.all_tasks() instead (#741) --- black.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 -- 2.39.5