diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2017-12-09 18:00:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-09 18:00:05 (GMT) |
commit | 28d8d14013ade0657fed4673f5fa3c08eb2b1944 (patch) | |
tree | 4c24b73040f8f13eafd9216c934f2d27218e91d8 /Lib/asyncio | |
parent | a9f8df646aac7fc94ced0aefd1ed2c8566d14d10 (diff) | |
download | cpython-28d8d14013ade0657fed4673f5fa3c08eb2b1944.zip cpython-28d8d14013ade0657fed4673f5fa3c08eb2b1944.tar.gz cpython-28d8d14013ade0657fed4673f5fa3c08eb2b1944.tar.bz2 |
bpo-32253: Deprecate with statement and bare await for asyncio locks (GH-4764)
* Add test for 'with (yield from lock)'
* Deprecate with statement for asyncio locks
* Document the deprecation
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/locks.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/asyncio/locks.py b/Lib/asyncio/locks.py index aa6ed3e..57eb69e 100644 --- a/Lib/asyncio/locks.py +++ b/Lib/asyncio/locks.py @@ -3,6 +3,7 @@ __all__ = ['Lock', 'Event', 'Condition', 'Semaphore', 'BoundedSemaphore'] import collections +import warnings from . import events from . import futures @@ -63,6 +64,9 @@ class _ContextManagerMixin: # <block> # finally: # lock.release() + warnings.warn("'with (yield from lock)' is deprecated " + "use 'async with lock' instead", + DeprecationWarning, stacklevel=2) yield from self.acquire() return _ContextManager(self) @@ -71,6 +75,9 @@ class _ContextManagerMixin: 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__() |