From 9afffacaa0e5ac911f9feacb916bc48473dcb117 Mon Sep 17 00:00:00 2001 From: Richard Si <63936253+ichard26@users.noreply.github.com> Date: Sat, 30 Oct 2021 18:35:55 -0400 Subject: [PATCH 1/1] Address mypy errors on 3.10 w/ asyncio loop parameter (#2580) --- CHANGES.md | 2 ++ src/black/__init__.py | 5 ++++- src/black/concurrency.py | 9 ++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 76a7ca6..c49516c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,8 @@ - Add new `--workers` parameter (#2514) - Fixed feature detection for positional-only arguments in lambdas (#2532) - Bumped typed-ast version minimum to 1.4.3 for 3.10 compatiblity (#2519) +- Fixed a Python 3.10 compatibility issue where the loop argument was still being passed + even though it has been removed (#2580) ### _Blackd_ diff --git a/src/black/__init__.py b/src/black/__init__.py index 5c6cb67..c503c1a 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -763,7 +763,10 @@ async def schedule_formatting( sources_to_cache.append(src) report.done(src, changed) if cancelled: - await asyncio.gather(*cancelled, loop=loop, return_exceptions=True) + if sys.version_info >= (3, 7): + await asyncio.gather(*cancelled, return_exceptions=True) + else: + await asyncio.gather(*cancelled, loop=loop, return_exceptions=True) if sources_to_cache: write_cache(cache, sources_to_cache, mode) diff --git a/src/black/concurrency.py b/src/black/concurrency.py index 69d79f5..24f67b6 100644 --- a/src/black/concurrency.py +++ b/src/black/concurrency.py @@ -42,9 +42,12 @@ def shutdown(loop: asyncio.AbstractEventLoop) -> None: for task in to_cancel: task.cancel() - loop.run_until_complete( - asyncio.gather(*to_cancel, loop=loop, return_exceptions=True) - ) + if sys.version_info >= (3, 7): + loop.run_until_complete(asyncio.gather(*to_cancel, return_exceptions=True)) + else: + loop.run_until_complete( + asyncio.gather(*to_cancel, loop=loop, return_exceptions=True) + ) finally: # `concurrent.futures.Future` objects cannot be cancelled once they # are already running. There might be some when the `shutdown()` happened. -- 2.39.5