8000 bpo-36373: Deprecate explicit loop parameter in all public asyncio AP… · python/cpython@bb8fc8b · GitHub
[go: up one dir, main page]

Skip to content

Commit bb8fc8b

Browse files
bpo-36373: Deprecate explicit loop parameter in all public asyncio APIs [locks] (GH-13920)
This PR deprecate explicit loop parameters in all public asyncio APIs This issues is split to be easier to review. Third step: locks.py https://bugs.python.org/issue36373 (cherry picked from commit 537877d) Co-authored-by: Emmanuel Arias <emmanuelarias30@gmail.com>
1 parent ab74e52 commit bb8fc8b

File tree

7 files changed

+419
-265
lines changed

7 files changed

+419
-265
lines changed

Doc/library/asyncio-sync.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ Lock
5959
finally:
6060
lock.release()
6161

62+
.. deprecated-removed:: 3.8 3.10
63+
The *loop* parameter.
64+
6265
.. coroutinemethod:: acquire()
6366

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

107+
108+
.. deprecated-removed:: 3.8 3.10
109+
The *loop* parameter.
110+
104111
.. _asyncio_example_sync_event:
105112

106113
Example::
@@ -173,6 +180,10 @@ Condition
173180
``None``. In the latter case a new Lock object is created
174181
automatically.
175182

183+
184+
.. deprecated-removed:: 3.8 3.10
185+
The *loop* parameter.
186+
176187
The preferred way to use a Condition is an :keyword:`async with`
177188
statement::
178189

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

283+
284+
.. deprecated-removed:: 3.8 3.10
285+
The *loop* parameter.
286+
272287
The preferred way to use a Semaphore is an :keyword:`async with`
273288
statement::
274289

@@ -322,6 +337,9 @@ BoundedSemaphore
322337
increases the internal counter above the initial *value*.
323338

324339

340+
.. deprecated-removed:: 3.8 3.10
341+
The *loop* parameter.
342+
325343
---------
326344

327345

Lib/asyncio/locks.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,13 @@ class Lock(_ContextManagerMixin):
160160
def __init__(self, *, loop=None):
161161
self._waiters = None
162162
self._locked = False
163-
if loop is not None:
164-
self._loop = loop
165-
else:
163+
if loop is None:
166164
self._loop = events.get_event_loop()
165+
else:
166+
self._loop = loop
167+
warnings.warn("The loop argument is deprecated since Python 3.8, "
168+
"and scheduled for removal in Python 3.10.",
169+
DeprecationWarning, stacklevel=2)
167170

168171
def __repr__(self):
169172
res = super().__repr__()
@@ -253,10 +256,13 @@ class Event:
253256
def __init__(self, *, loop=None):
254257
self._waiters = collections.deque()
255258
self._value = False
256-
if loop is not None:
257-
self._loop = loop
258-
else:
259+
if loop is None:
259260
self._loop = events.get_event_loop()
261+
else:
262+
self._loop = loop
263+
warnings.warn("The loop argument is deprecated since Python 3.8, "
264+
"and scheduled for removal in Python 3.10.",
265+
DeprecationWarning, stacklevel=2)
260266

261267
def __repr__(self):
262268
res = super().__repr__()
@@ -317,10 +323,13 @@ class Condition(_ContextManagerMixin):
317323
"""
318324

319325
def __init__(self, lock=None, *, loop=None):
320-
if loop is not None:
321-
self._loop = loop
322-
else:
326+
if loop is None:
323327
self._loop = events.get_event_loop()
328+
else:
329+
self._loop = loop
330+
warnings.warn("The loop argument is deprecated since Python 3.8, "
331+
"and scheduled for removal in Python 3.10.",
332+
DeprecationWarning, stacklevel=2)
324333

325334
if lock is None:
326335
lock = Lock(loop=self._loop)
@@ -445,10 +454,13 @@ def __init__(self, value=1, *, loop=None):
445454
raise ValueError("Semaphore initial value must be >= 0")
446455
self._value = value
447456
self._waiters = collections.deque()
448-
if loop is not None:
449-
self._loop = loop
450-
else:
457+
if loop is None:
451458
self._loop = events.get_event_loop()
459+
else:
460+
self._loop = loop
461+
warnings.warn("The loop argument is deprecated since Python 3.8, "
462+
"and scheduled for removal in Python 3.10.",
463+
DeprecationWarning, stacklevel=2)
452464

453465
def __repr__(self):
454466
res = super().__repr__()
@@ -508,6 +520,11 @@ class BoundedSemaphore(Semaphore):
508520
"""
509521

510522
def __init__(self, value=1, *, loop=None):
523+
if loop:
524+
warnings.warn("The loop argument is deprecated since Python 3.8, "
525+
"and scheduled for removal in Python 3.10.",
526+
DeprecationWarning, stacklevel=2)
527+
511528
self._bound_value = value
512529
super().__init__(value, loop=loop)
513530

0 commit comments

Comments
 (0)
0