Skip to content

bpo-36373: Deprecate explicit loop parameter in all public asyncio APIs [locks] #13920

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

Merged
merged 5 commits into from
Sep 10, 2019
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
18 changes: 18 additions & 0 deletions Doc/library/asyncio-sync.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Lock
finally:
lock.release()

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

.. coroutinemethod:: acquire()

Acquire the lock.
Expand Down Expand Up @@ -101,6 +104,10 @@ Event
:meth:`clear` method. The :meth:`wait` method blocks until the
flag is set to *true*. The flag is set to *false* initially.


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

.. _asyncio_example_sync_event:

Example::
Expand Down Expand Up @@ -173,6 +180,10 @@ Condition
``None``. In the latter case a new Lock object is created
automatically.


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

The preferred way to use a Condition is an :keyword:`async with`
statement::

Expand Down Expand Up @@ -269,6 +280,10 @@ Semaphore
internal counter (``1`` by default). If the given value is
less than ``0`` a :exc:`ValueError` is raised.


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

The preferred way to use a Semaphore is an :keyword:`async with`
statement::

Expand Down Expand Up @@ -322,6 +337,9 @@ BoundedSemaphore
increases the internal counter above the initial *value*.


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

---------


Expand Down
41 changes: 29 additions & 12 deletions Lib/asyncio/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,13 @@ class Lock(_ContextManagerMixin):
def __init__(self, *, loop=None):
self._waiters = None
self._locked = False
if loop is not None:
self._loop = loop
else:
if loop is None:
self._loop = events.get_event_loop()
else:
self._loop = loop
warnings.warn("The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)

def __repr__(self):
res = super().__repr__()
Expand Down Expand Up @@ -253,10 +256,13 @@ class Event:
def __init__(self, *, loop=None):
self._waiters = collections.deque()
self._value = False
if loop is not None:
self._loop = loop
else:
if loop is None:
self._loop = events.get_event_loop()
else:
self._loop = loop
warnings.warn("The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)

def __repr__(self):
res = super().__repr__()
Expand Down Expand Up @@ -317,10 +323,13 @@ class Condition(_ContextManagerMixin):
"""

def __init__(self, lock=None, *, loop=None):
if loop is not None:
self._loop = loop
else:
if loop is None:
self._loop = events.get_event_loop()
else:
self._loop = loop
warnings.warn("The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)

if lock is None:
lock = Lock(loop=self._loop)
Expand Down Expand Up @@ -445,10 +454,13 @@ def __init__(self, value=1, *, loop=None):
raise ValueError("Semaphore initial value must be >= 0")
self._value = value
self._waiters = collections.deque()
if loop is not None:
self._loop = loop
else:
if loop is None:
self._loop = events.get_event_loop()
else:
self._loop = loop
warnings.warn("The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)

def __repr__(self):
res = super().__repr__()
Expand Down Expand Up @@ -508,6 +520,11 @@ class BoundedSemaphore(Semaphore):
"""

def __init__(self, value=1, *, loop=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)

self._bound_value = value
super().__init__(value, loop=loop)

Expand Down
Loading