summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2020-02-01 11:12:52 (GMT)
committerGitHub <noreply@github.com>2020-02-01 11:12:52 (GMT)
commit90d9ba6ef10af32e8dfe0649789c3a8ccf419e95 (patch)
tree5cd3e31fa3f1508ff72bfa0991bcdd8eeb9e3259 /Lib/asyncio
parentabb9a448dee3e18c69080231fbeba980bf048211 (diff)
downloadcpython-90d9ba6ef10af32e8dfe0649789c3a8ccf419e95.zip
cpython-90d9ba6ef10af32e8dfe0649789c3a8ccf419e95.tar.gz
cpython-90d9ba6ef10af32e8dfe0649789c3a8ccf419e95.tar.bz2
bpo-34793: Drop old-style context managers in asyncio.locks (GH-17533)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/locks.py83
1 files changed, 0 insertions, 83 deletions
diff --git a/Lib/asyncio/locks.py b/Lib/asyncio/locks.py
index d94daeb..f1ce732 100644
--- a/Lib/asyncio/locks.py
+++ b/Lib/asyncio/locks.py
@@ -3,96 +3,13 @@
__all__ = ('Lock', 'Event', 'Condition', 'Semaphore', 'BoundedSemaphore')
import collections
-import types
import warnings
from . import events
-from . import futures
from . import exceptions
-from .import coroutines
-
-
-class _ContextManager:
- """Context manager.
-
- This enables the following idiom for acquiring and releasing a
- lock around a block:
-
- with (yield from lock):
- <block>
-
- while failing loudly when accidentally using:
-
- with lock:
- <block>
-
- Deprecated, use 'async with' statement:
- async with lock:
- <block>
- """
-
- def __init__(self, lock):
- self._lock = lock
-
- def __enter__(self):
- # We have no use for the "as ..." clause in the with
- # statement for locks.
- return None
-
- def __exit__(self, *args):
- try:
- self._lock.release()
- finally:
- self._lock = None # Crudely prevent reuse.
class _ContextManagerMixin:
- def __enter__(self):
- raise RuntimeError(
- '"yield from" should be used as context manager expression')
-
- def __exit__(self, *args):
- # This must exist because __enter__ exists, even though that
- # always raises; that's how the with-statement works.
- pass
-
- @types.coroutine
- def __iter__(self):
- # This is not a coroutine. It is meant to enable the idiom:
- #
- # with (yield from lock):
- # <block>
- #
- # as an alternative to:
- #
- # yield from lock.acquire()
- # try:
- # <block>
- # finally:
- # lock.release()
- # Deprecated, use 'async with' statement:
- # async with lock:
- # <block>
- warnings.warn("'with (yield from lock)' is deprecated "
- "use 'async with lock' instead",
- DeprecationWarning, stacklevel=2)
- yield from self.acquire()
- return _ContextManager(self)
-
- # The flag is needed for legacy asyncio.iscoroutine()
- __iter__._is_coroutine = coroutines._is_coroutine
-
- async def __acquire_ctx(self):
- await self.acquire()
- return _ContextManager(self)
-
- def __await__(self):
- warnings.warn("'with await lock' is deprecated "
- "use 'async with lock' instead",
- DeprecationWarning, stacklevel=2)
- # To make "with await lock" work.
- return self.__acquire_ctx().__await__()
-
async def __aenter__(self):
await self.acquire()
# We have no use for the "as ..." clause in the with