bpo-37658: Actually return result in race condition (GH-29202)
(cherry picked from commit 934a82623793e9d52b85f74d5395d65927a52205)
Co-authored-by: Sam Bull <aa6bs0@sambull.org>
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 9a9d0d6..53eef84 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -415,11 +415,9 @@ async def wait_for(fut, timeout):
await _cancel_and_wait(fut, loop=loop)
try:
- fut.result()
+ return fut.result()
except exceptions.CancelledError as exc:
raise exceptions.TimeoutError() from exc
- else:
- raise exceptions.TimeoutError()
waiter = loop.create_future()
timeout_handle = loop.call_later(timeout, _release_waiter, waiter)
@@ -455,11 +453,9 @@ async def wait_for(fut, timeout):
# exception, we should re-raise it
# See https://bugs.python.org/issue40607
try:
- fut.result()
+ return fut.result()
except exceptions.CancelledError as exc:
raise exceptions.TimeoutError() from exc
- else:
- raise exceptions.TimeoutError()
finally:
timeout_handle.cancel()