Skip to content

Commit b3d605d

Browse files
committed
Do not pass coroutine objects directly to asyncio.wait()
Fixes The explicit passing of coroutine objects to asyncio.wait() is deprecated since Python 3.8, and scheduled for removal in Python 3.11. This has been “deprecated as it leads to confusing behavior”. See https://docs.python.org/3.8/library/asyncio-task.html#asyncio-example-wait-coroutine and https://stackoverflow.com/questions/69889075/asyncio-wait-confusion-when-passed-a-coroutine
1 parent dde5015 commit b3d605d

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

tests/ext/aiohttp/test_middleware.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,9 @@ async def get_delay():
287287
assert resp.status == 200
288288

289289
if sys.version_info >= (3, 8):
290-
await asyncio.wait([get_delay(), get_delay(), get_delay(),
291-
get_delay(), get_delay(), get_delay(),
292-
get_delay(), get_delay(), get_delay()])
290+
await asyncio.wait([loop.create_task(get_delay()) for i in range(9)])
293291
else:
294-
await asyncio.wait([get_delay(), get_delay(), get_delay(),
295-
get_delay(), get_delay(), get_delay(),
296-
get_delay(), get_delay(), get_delay()],
297-
loop=loop)
292+
await asyncio.wait([loop.create_task(get_delay()) for i in range(9)], loop=loop)
298293

299294
# Ensure all ID's are different
300295
ids = [item.id for item in recorder.emitter.local]

tests/test_async_local_storage.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ async def _test():
3535
# Run loads of concurrent tasks
3636
if sys.version_info >= (3, 8):
3737
results = event_loop.run_until_complete(
38-
asyncio.wait([_test() for _ in range(0, 100)])
38+
asyncio.wait([event_loop.create_task(_test()) for _ in range(0, 100)])
3939
)
4040
else:
4141
results = event_loop.run_until_complete(
42-
asyncio.wait([_test() for _ in range(0, 100)], loop=event_loop)
42+
asyncio.wait(
43+
[event_loop.create_task(_test()) for _ in range(0, 100)],
44+
loop=event_loop,
45+
)
4346
)
4447
results = [item.result() for item in results[0]]
4548

0 commit comments

Comments
 (0)