Skip to content

Commit 89aa7f0

Browse files
aerosasvetlov
authored andcommitted
bpo-34790: Implement deprecation of passing coroutines to asyncio.wait() (GH-16977)
1 parent 88dce26 commit 89aa7f0

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

Doc/whatsnew/3.9.rst

+3
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ Deprecated
290290
predicable behavior.
291291
(Contributed by Serhiy Storchaka in :issue:`38371`.)
292292

293+
* The explicit passing of coroutine objects to :func:`asyncio.wait` has been
294+
deprecated and will be removed in version 3.11.
295+
(Contributed by Yury Selivanov and Kyle Stanley in :issue:`34790`.)
293296

294297
Removed
295298
=======

Lib/asyncio/tasks.py

+6
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,12 @@ async def wait(fs, *, loop=None, timeout=None, return_when=ALL_COMPLETED):
424424
"and scheduled for removal in Python 3.10.",
425425
DeprecationWarning, stacklevel=2)
426426

427+
if any(coroutines.iscoroutine(f) for f in set(fs)):
428+
warnings.warn("The explicit passing of coroutine objects to "
429+
"asyncio.wait() is deprecated since Python 3.8, and "
430+
"scheduled for removal in Python 3.11.",
431+
DeprecationWarning, stacklevel=2)
432+
427433
fs = {ensure_future(f, loop=loop) for f in set(fs)}
428434

429435
return await _wait(fs, timeout, return_when, loop)

Lib/test/test_asyncio/test_tasks.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -979,12 +979,12 @@ def test_wait_duplicate_coroutines(self):
979979
def coro(s):
980980
return s
981981
c = coro('test')
982-
983-
task =self.new_task(
982+
task = self.new_task(
984983
self.loop,
985984
asyncio.wait([c, c, coro('spam')]))
986985

987-
done, pending = self.loop.run_until_complete(task)
986+
with self.assertWarns(DeprecationWarning):
987+
done, pending = self.loop.run_until_complete(task)
988988

989989
self.assertFalse(pending)
990990
self.assertEqual(set(f.result() for f in done), {'test', 'spam'})
@@ -1346,7 +1346,9 @@ def gen():
13461346
futs = list(asyncio.as_completed(fs, loop=loop))
13471347
self.assertEqual(len(futs), 2)
13481348
waiter = asyncio.wait(futs)
1349-
done, pending = loop.run_until_complete(waiter)
1349+
# Deprecation from passing coros in futs to asyncio.wait()
1350+
with self.assertWarns(DeprecationWarning):
1351+
done, pending = loop.run_until_complete(waiter)
13501352
self.assertEqual(set(f.result() for f in done), {'a', 'b'})
13511353

13521354
def test_as_completed_duplicate_coroutines(self):
@@ -1751,7 +1753,8 @@ async def inner():
17511753

17521754
async def outer():
17531755
nonlocal proof
1754-
d, p = await asyncio.wait([inner()])
1756+
with self.assertWarns(DeprecationWarning):
1757+
d, p = await asyncio.wait([inner()])
17551758
proof += 100
17561759

17571760
f = asyncio.ensure_future(outer(), loop=self.loop)
@@ -3307,6 +3310,17 @@ def test_loop_argument_is_deprecated_in_wait_for(self):
33073310
self.loop.run_until_complete(
33083311
asyncio.wait_for(coroutine_function(), 0.01, loop=self.loop))
33093312

3313+
def test_coro_is_deprecated_in_wait(self):
3314+
# Remove test when passing coros to asyncio.wait() is removed in 3.11
3315+
with self.assertWarns(DeprecationWarning):
3316+
self.loop.run_until_complete(
3317+
asyncio.wait([coroutine_function()]))
3318+
3319+
task = self.loop.create_task(coroutine_function())
3320+
with self.assertWarns(DeprecationWarning):
3321+
self.loop.run_until_complete(
3322+
asyncio.wait([task, coroutine_function()]))
3323+
33103324

33113325
class CompatibilityTests(test_utils.TestCase):
33123326
# Tests for checking a bridge between old-styled coroutines

0 commit comments

Comments
 (0)