mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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:
parent
a9f8df646a
commit
28d8d14013
5 changed files with 108 additions and 55 deletions
|
@ -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__()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue