Skip to content

bpo-36373: Deprecate explicit loop parameter in all public asyncio APIs [task] [WIP] #13670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
12 changes: 12 additions & 0 deletions Doc/library/asyncio-task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ Running Tasks Concurrently
cancellation of one submitted Task/Future to cause other
Tasks/Futures to be cancelled.

.. deprecated-removed:: 3.8 3.10
The *loop* parameter.

.. _asyncio_example_gather:

Example::
Expand Down Expand Up @@ -411,6 +414,9 @@ Shielding From Cancellation
except CancelledError:
res = None

.. deprecated-removed:: 3.8 3.10
The *loop* parameter.


Timeouts
========
Expand Down Expand Up @@ -568,6 +574,9 @@ Waiting Primitives
Raises :exc:`asyncio.TimeoutError` if the timeout occurs before
all Futures are done.

.. deprecated-removed:: 3.8 3.10
The *loop* parameter.

Example::

for f in as_completed(aws):
Expand Down Expand Up @@ -694,6 +703,9 @@ Task Object
.. versionchanged:: 3.8
Added the ``name`` parameter.

.. deprecated-removed:: 3.8 3.10
The *loop* parameter.

.. method:: cancel()

Request the Task to be cancelled.
Expand Down
25 changes: 24 additions & 1 deletion Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def all_tasks(cls, loop=None):
return _all_tasks_compat(loop)

def __init__(self, coro, *, loop=None, name=None):
warnings.warn("The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)
super().__init__(loop=loop)
if self._source_traceback:
del self._source_traceback[-1]
Expand Down Expand Up @@ -544,7 +547,12 @@ def as_completed(fs, *, loop=None, timeout=None):
"""
if futures.isfuture(fs) or coroutines.iscoroutine(fs):
raise TypeError(f"expect a list of futures, not {type(fs).__name__}")
loop = loop if loop is not None else events.get_event_loop()
if loop is None:
loop = events.get_event_loop()
else:
warnings.warn("The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)
todo = {ensure_future(f, loop=loop) for f in set(fs)}
from .queues import Queue # Import here to avoid circular import problem.
done = Queue(loop=loop)
Expand Down Expand Up @@ -619,6 +627,10 @@ def ensure_future(coro_or_future, *, loop=None):

If the argument is a Future, it is returned directly.
"""
if loop:
warnings.warn("The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)
if coroutines.iscoroutine(coro_or_future):
if loop is None:
loop = events.get_event_loop()
Expand Down Expand Up @@ -659,6 +671,9 @@ class _GatheringFuture(futures.Future):
"""

def __init__(self, children, *, loop=None):
warnings.warn("The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)
super().__init__(loop=loop)
self._children = children
self._cancel_requested = False
Expand Down Expand Up @@ -704,6 +719,10 @@ def gather(*coros_or_futures, loop=None, return_exceptions=False):
if not coros_or_futures:
if loop is None:
loop = events.get_event_loop()
else:
warnings.warn("The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)
outer = loop.create_future()
outer.set_result([])
return outer
Expand Down Expand Up @@ -813,6 +832,10 @@ def shield(arg, *, loop=None):
except CancelledError:
res = None
"""
if loop:
warnings.warn("The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)
inner = ensure_future(arg, loop=loop)
if inner.done():
# Shortcut.
Expand Down
Loading