Commit d00eac99 authored by Hugo's avatar Hugo Committed by Łukasz Langa
Browse files

Fix PendingDeprecationWarning: Task.all_tasks() is deprecated, use...

Fix PendingDeprecationWarning: Task.all_tasks() is deprecated, use asyncio.all_tasks() instead (#741)
parent 53e72102
Loading
Loading
Loading
Loading
+5 −1
Changes for black.py: 5 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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