From b611b6473776bba1c55878a0996e9e1e60118331 Mon Sep 17 00:00:00 2001 From: Cooper Ry Lees Date: Wed, 13 Jul 2022 05:00:20 +0000 Subject: [PATCH 1/5] Move to explicitly creating a new loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - >= 3.10 add a warning that `get_event_loop` will not automatically create a loop - Move to explicit API Test: - `python3.11 -m venv --upgrade-deps /tmp/tb` - `/tmp/tb/bin/pip install -e .` - Install deps and no blackd as aiohttp + yarl can't build still with 3.11 - https://github.com/aio-libs/aiohttp/issues/6600 - `export PYTHONWARNINGS=error` ``` cooper@l33t:~/repos/black$ /tmp/tb/bin/black . All done! ✨ 🍰 ✨ 44 files left unchanged. ``` Fixes #3110 --- src/black/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/black/__init__.py b/src/black/__init__.py index 2d04cf81910..4ad69acd01f 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -773,7 +773,6 @@ def reformat_many( from concurrent.futures import Executor, ThreadPoolExecutor, ProcessPoolExecutor executor: Executor - loop = asyncio.get_event_loop() worker_count = workers if workers is not None else DEFAULT_WORKERS if sys.platform == "win32": # Work around https://bugs.python.org/issue26903 @@ -788,6 +787,7 @@ def reformat_many( # any good due to the Global Interpreter Lock) executor = ThreadPoolExecutor(max_workers=1) + loop = asyncio.new_event_loop() try: loop.run_until_complete( schedule_formatting( From 16d3127e1a4bd83644e45b5871cdc7135c768291 Mon Sep 17 00:00:00 2001 From: Cooper Ry Lees Date: Wed, 13 Jul 2022 05:11:11 +0000 Subject: [PATCH 2/5] Add to CHANGES.md --- CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index a0607edefa5..6b9edef99ea 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -39,6 +39,9 @@ +- Change from deprecated `asyncio.get_event_loop()` to create out event loop which + removes DesprecationWarning (#3164) + ### Packaging From c68563b942160f80b084ccefffdf7fbbf99292bb Mon Sep 17 00:00:00 2001 From: Cooper Ry Lees Date: Wed, 13 Jul 2022 05:12:10 +0000 Subject: [PATCH 3/5] Fix a cooper typo yet again --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 6b9edef99ea..e61dedf5272 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -39,7 +39,7 @@ -- Change from deprecated `asyncio.get_event_loop()` to create out event loop which +- Change from deprecated `asyncio.get_event_loop()` to create our event loop which removes DesprecationWarning (#3164) ### Packaging From 082c98d47bb46401b130e0d52c7301bf329e967d Mon Sep 17 00:00:00 2001 From: Cooper Ry Lees Date: Wed, 13 Jul 2022 21:51:20 +0000 Subject: [PATCH 4/5] Set default asyncio loop to our explicitly created one + unset on exit --- src/black/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/black/__init__.py b/src/black/__init__.py index 4ad69acd01f..d2df1cbee7c 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -788,6 +788,7 @@ def reformat_many( executor = ThreadPoolExecutor(max_workers=1) loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) try: loop.run_until_complete( schedule_formatting( @@ -801,7 +802,10 @@ def reformat_many( ) ) finally: - shutdown(loop) + try: + shutdown(loop) + finally: + asyncio.set_event_loop(None) if executor is not None: executor.shutdown() From d2862de7a67f8d72fe46f93cf65aada1123aa754 Mon Sep 17 00:00:00 2001 From: Cooper Lees Date: Thu, 14 Jul 2022 12:09:19 -0700 Subject: [PATCH 5/5] Update CHANGES.md Fix my silly typo. Co-authored-by: Thomas Grainger --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index e61dedf5272..4513cdf5141 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -40,7 +40,7 @@ - Change from deprecated `asyncio.get_event_loop()` to create our event loop which - removes DesprecationWarning (#3164) + removes DeprecationWarning (#3164) ### Packaging