Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 16 additions & 3 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@ async def wait(fs, *, loop=None, timeout=None, return_when=ALL_COMPLETED):
raise ValueError(f'Invalid return_when value: {return_when}')

if loop is None:
loop = events.get_event_loop()
loop = events.get_running_loop()
else:
warnings.warn("The loop argument is deprecated and scheduled for"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the warning messages are missing spaces (between "for" and "removal").

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. @joaojunior please submit another PR to fix this.

@willingc I don't think @asvetlov had a chance to review this PR :(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@1st1 Ok, I will send.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Sorry @1st and @asvetlov. I messed up on that. 😞

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joaojunior never mind, it's handled in #9579

"removal in Python 4.0.",
DeprecationWarning, stacklevel=2)

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

Expand All @@ -408,7 +412,11 @@ async def wait_for(fut, timeout, *, loop=None):
This function is a coroutine.
"""
if loop is None:
loop = events.get_event_loop()
loop = events.get_running_loop()
else:
warnings.warn("The loop argument is deprecated and scheduled for"
"removal in Python 4.0.",
DeprecationWarning, stacklevel=2)

if timeout is None:
return await fut
Expand Down Expand Up @@ -585,7 +593,12 @@ async def sleep(delay, result=None, *, loop=None):
return result

if loop is None:
loop = events.get_event_loop()
loop = events.get_running_loop()
else:
warnings.warn("The loop argument is deprecated and scheduled for"
"removal in Python 4.0.",
DeprecationWarning, stacklevel=2)

future = loop.create_future()
h = loop.call_later(delay,
futures._set_result_unless_cancelled,
Expand Down
29 changes: 29 additions & 0 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3220,6 +3220,35 @@ def coro():
self.loop.run_until_complete(coro())
self.assertEqual(result, 11)

def test_loop_argument_is_deprecated(self):
# Remove test when loop argument is removed in Python 4.0
with self.assertWarns(DeprecationWarning):
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))


class WaitTests(test_utils.TestCase):
def setUp(self):
super().setUp()
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(None)

def tearDown(self):
self.loop.close()
self.loop = None
super().tearDown()

def test_loop_argument_is_deprecated_in_wait(self):
# Remove test when loop argument is removed in Python 4.0
with self.assertWarns(DeprecationWarning):
self.loop.run_until_complete(
asyncio.wait([coroutine_function()], loop=self.loop))

def test_loop_argument_is_deprecated_in_wait_for(self):
# Remove test when loop argument is removed in Python 4.0
with self.assertWarns(DeprecationWarning):
self.loop.run_until_complete(
asyncio.wait_for(coroutine_function(), 0.01, loop=self.loop))


class CompatibilityTests(test_utils.TestCase):
# Tests for checking a bridge between old-styled coroutines
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add deprecation warning when `loop` is used in methods: `asyncio.sleep`,
`asyncio.wait` and `asyncio.wait_for`.