mirror of
https://github.com/python/cpython.git
synced 2025-08-31 22:18:28 +00:00
bpo-34728: Remove deprecate *loop* argument in asyncio.sleep (GH-9415)
* Insert the warn in the asyncio.sleep when the loop argument is used * Insert the warn in the asyncio.wait and asyncio.wait_for when the loop argument is used * Better format of the code * Add news file * change calls for get_event_loop() to calls for get_running_loop() * Change message to be more clear in News * Improve the comments in test_tasks
This commit is contained in:
parent
a0fd7f1b55
commit
558c49bcf3
3 changed files with 47 additions and 3 deletions
|
@ -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"
|
||||
"removal in Python 4.0.",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
|
||||
fs = {ensure_future(f, loop=loop) for f in set(fs)}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue