bpo-32363: Disable Task.set_exception() and Task.set_result() (#4923)

This commit is contained in:
Yury Selivanov 2017-12-25 10:48:15 -05:00 committed by GitHub
parent 3dfbaf51f0
commit 0cf16f9ea0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 158 additions and 44 deletions

View file

@ -239,14 +239,15 @@ class Future:
self._schedule_callbacks()
self._log_traceback = True
def __iter__(self):
def __await__(self):
if not self.done():
self._asyncio_future_blocking = True
yield self # This tells Task to wait for completion.
assert self.done(), "await wasn't used with future"
if not self.done():
raise RuntimeError("await wasn't used with future")
return self.result() # May raise too.
__await__ = __iter__ # make compatible with 'await' expression
__iter__ = __await__ # make compatible with 'yield from'.
# Needed for testing purposes.