summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2017-12-11 17:35:49 +0200
committerGitHub <noreply@github.com>2017-12-11 17:35:49 +0200
commit8874342cf332c3aa3d845155cc4b41b00c2d9e9d (patch)
tree79b2b2a3413fde605670e995428e64144a509f77 /Lib
parentabae67ebc2897ca37df067f322d19e19d1ef6d88 (diff)
downloadcpython-git-8874342cf332c3aa3d845155cc4b41b00c2d9e9d.tar.gz
bpo-32258: Replace 'yield from' to 'await' in asyncio docs (#4779)
* Replace 'yield from' to 'await' in asyncio docs * Fix docstrings
Diffstat (limited to 'Lib')
-rw-r--r--Lib/asyncio/coroutines.py5
-rw-r--r--Lib/asyncio/futures.py5
-rw-r--r--Lib/asyncio/locks.py19
3 files changed, 19 insertions, 10 deletions
diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py
index d7e6b4c1cc..bca7fe3a53 100644
--- a/Lib/asyncio/coroutines.py
+++ b/Lib/asyncio/coroutines.py
@@ -19,8 +19,9 @@ def _is_debug_mode():
# If you set _DEBUG to true, @coroutine will wrap the resulting
# generator objects in a CoroWrapper instance (defined below). That
# instance will log a message when the generator is never iterated
- # over, which may happen when you forget to use "yield from" with a
- # coroutine call. Note that the value of the _DEBUG flag is taken
+ # over, which may happen when you forget to use "await" or "yield from"
+ # with a coroutine call.
+ # Note that the value of the _DEBUG flag is taken
# when the decorator is used, so to be of any use it must be set
# before you define your coroutines. A downside of using this feature
# is that tracebacks show entries for the CoroWrapper.__next__ method
diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py
index b805f99896..d46a295197 100644
--- a/Lib/asyncio/futures.py
+++ b/Lib/asyncio/futures.py
@@ -59,7 +59,8 @@ class Future:
# The value must also be not-None, to enable a subclass to declare
# that it is not compatible by setting this to None.
# - It is set by __iter__() below so that Task._step() can tell
- # the difference between `yield from Future()` (correct) vs.
+ # the difference between
+ # `await Future()` or`yield from Future()` (correct) vs.
# `yield Future()` (incorrect).
_asyncio_future_blocking = False
@@ -236,7 +237,7 @@ class Future:
if not self.done():
self._asyncio_future_blocking = True
yield self # This tells Task to wait for completion.
- assert self.done(), "yield from wasn't used with future"
+ assert self.done(), "await wasn't used with future"
return self.result() # May raise too.
__await__ = __iter__ # make compatible with 'await' expression
diff --git a/Lib/asyncio/locks.py b/Lib/asyncio/locks.py
index 54f6258598..6193837350 100644
--- a/Lib/asyncio/locks.py
+++ b/Lib/asyncio/locks.py
@@ -23,6 +23,10 @@ class _ContextManager:
with lock:
<block>
+
+ Deprecated, use 'async with' statement:
+ async with lock:
+ <block>
"""
def __init__(self, lock):
@@ -64,6 +68,9 @@ class _ContextManagerMixin:
# <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)
@@ -113,16 +120,16 @@ class Lock(_ContextManagerMixin):
release() call resets the state to unlocked; first coroutine which
is blocked in acquire() is being processed.
- acquire() is a coroutine and should be called with 'yield from'.
+ acquire() is a coroutine and should be called with 'await'.
- Locks also support the context management protocol. '(yield from lock)'
- should be used as the context manager expression.
+ Locks also support the asynchronous context management protocol.
+ 'async with lock' statement should be used.
Usage:
lock = Lock()
...
- yield from lock
+ await lock.acquire()
try:
...
finally:
@@ -132,13 +139,13 @@ class Lock(_ContextManagerMixin):
lock = Lock()
...
- with (yield from lock):
+ async with lock:
...
Lock objects can be tested for locking state:
if not lock.locked():
- yield from lock
+ await lock.acquire()
else:
# lock is acquired
...