summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-11-18 12:40:41 -0500
committerYury Selivanov <yselivanov@sprymix.com>2015-11-18 12:40:41 -0500
commit5c9f204300d9ed0e9433bc9b3ce5da0249ca0b24 (patch)
treec45e69a80063e88ec8c7f0a2591275be1679840c
parent66f6238fca7286a3917eab0e9fafd7aa6f8e90a4 (diff)
parent576fe71c12502349aab70f0b2b0c84ca72b47165 (diff)
downloadcpython-git-5c9f204300d9ed0e9433bc9b3ce5da0249ca0b24.tar.gz
Merge 3.5
-rw-r--r--Lib/asyncio/coroutines.py8
-rw-r--r--Lib/test/test_asyncio/test_pep492.py20
2 files changed, 27 insertions, 1 deletions
diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py
index e11b21b097..3a92c7d755 100644
--- a/Lib/asyncio/coroutines.py
+++ b/Lib/asyncio/coroutines.py
@@ -140,7 +140,13 @@ class CoroWrapper:
if compat.PY35:
- __await__ = __iter__ # make compatible with 'await' expression
+ def __await__(self):
+ cr_await = getattr(self.gen, 'cr_await', None)
+ if cr_await is not None:
+ raise RuntimeError(
+ "Cannot await on coroutine {!r} while it's "
+ "awaiting for {!r}".format(self.gen, cr_await))
+ return self
@property
def gi_yieldfrom(self):
diff --git a/Lib/test/test_asyncio/test_pep492.py b/Lib/test/test_asyncio/test_pep492.py
index 41e1b8a9e0..404a7489ae 100644
--- a/Lib/test/test_asyncio/test_pep492.py
+++ b/Lib/test/test_asyncio/test_pep492.py
@@ -203,6 +203,26 @@ class CoroutineTests(BaseTest):
self.loop.run_until_complete(runner())
+ def test_double_await(self):
+ async def afunc():
+ await asyncio.sleep(0.1, loop=self.loop)
+
+ async def runner():
+ coro = afunc()
+ t = asyncio.Task(coro, loop=self.loop)
+ try:
+ await asyncio.sleep(0, loop=self.loop)
+ await coro
+ finally:
+ t.cancel()
+
+ self.loop.set_debug(True)
+ with self.assertRaisesRegex(
+ RuntimeError,
+ r'Cannot await.*test_double_await.*\bafunc\b.*while.*\bsleep\b'):
+
+ self.loop.run_until_complete(runner())
+
if __name__ == '__main__':
unittest.main()