Address mypy errors on 3.10 w/ asyncio loop parameter (#2580)

This commit is contained in:
Richard Si 2021-10-30 18:35:55 -04:00 committed by GitHub
parent fac498bf31
commit 9afffacaa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -8,6 +8,8 @@
- Add new `--workers` parameter (#2514) - Add new `--workers` parameter (#2514)
- Fixed feature detection for positional-only arguments in lambdas (#2532) - Fixed feature detection for positional-only arguments in lambdas (#2532)
- Bumped typed-ast version minimum to 1.4.3 for 3.10 compatiblity (#2519) - 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_ ### _Blackd_

View File

@ -763,6 +763,9 @@ async def schedule_formatting(
sources_to_cache.append(src) sources_to_cache.append(src)
report.done(src, changed) report.done(src, changed)
if cancelled: if cancelled:
if sys.version_info >= (3, 7):
await asyncio.gather(*cancelled, return_exceptions=True)
else:
await asyncio.gather(*cancelled, loop=loop, return_exceptions=True) await asyncio.gather(*cancelled, loop=loop, return_exceptions=True)
if sources_to_cache: if sources_to_cache:
write_cache(cache, sources_to_cache, mode) write_cache(cache, sources_to_cache, mode)

View File

@ -42,6 +42,9 @@ def shutdown(loop: asyncio.AbstractEventLoop) -> None:
for task in to_cancel: for task in to_cancel:
task.cancel() task.cancel()
if sys.version_info >= (3, 7):
loop.run_until_complete(asyncio.gather(*to_cancel, return_exceptions=True))
else:
loop.run_until_complete( loop.run_until_complete(
asyncio.gather(*to_cancel, loop=loop, return_exceptions=True) asyncio.gather(*to_cancel, loop=loop, return_exceptions=True)
) )