summaryrefslogtreecommitdiff
path: root/Lib/asyncio/locks.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2017-12-09 20:00:05 +0200
committerGitHub <noreply@github.com>2017-12-09 20:00:05 +0200
commit28d8d14013ade0657fed4673f5fa3c08eb2b1944 (patch)
tree4c24b73040f8f13eafd9216c934f2d27218e91d8 /Lib/asyncio/locks.py
parenta9f8df646aac7fc94ced0aefd1ed2c8566d14d10 (diff)
downloadcpython-git-28d8d14013ade0657fed4673f5fa3c08eb2b1944.tar.gz
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/locks.py')
-rw-r--r--Lib/asyncio/locks.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/asyncio/locks.py b/Lib/asyncio/locks.py
index aa6ed3eaea..57eb69e7cf 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__()