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
This commit is contained in:
Andrew Svetlov 2017-12-09 20:00:05 +02:00 committed by GitHub
parent a9f8df646a
commit 28d8d14013
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 108 additions and 55 deletions

View file

@ -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__()