Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Implement deprecation of passing coros to asyncio.wait()
  • Loading branch information
aeros committed Oct 29, 2019
commit 6e30ac407e4cb618e4bc883f857380366e8fb682
5 changes: 5 additions & 0 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ async def wait(fs, *, loop=None, timeout=None, return_when=ALL_COMPLETED):
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)

if any(coroutines.iscoroutine(f) for f in set(fs)):
warnings.warn("Passing coroutines objects to asyncio.wait() is "
"deprecated since Python 3.8, and scheduled for removal "
"in Python 3.11", DeprecationWarning)

fs = {ensure_future(f, loop=loop) for f in set(fs)}

return await _wait(fs, timeout, return_when, loop)
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3307,6 +3307,19 @@ def test_loop_argument_is_deprecated_in_wait_for(self):
self.loop.run_until_complete(
asyncio.wait_for(coroutine_function(), 0.01, loop=self.loop))

def test_coro_is_deprecated_in_wait(self):
# Remove test when passing coros to asyncio.wait() is removed in 3.11
# Test with coro as first arg
with self.assertWarns(DeprecationWarning):
self.loop.run_until_complete(
asyncio.wait([coroutine_function()]))

# Test with coro as second arg
task = self.loop.create_task(coroutine_function())
with self.assertWarns(DeprecationWarning):
self.loop.run_until_complete(
asyncio.wait([task, coroutine_function()]))


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