diff options
author | Guido van Rossum <guido@python.org> | 2016-09-09 12:54:54 -0700 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2016-09-09 12:54:54 -0700 |
commit | 753c693708b34d559ff82a9a8fcb06c4e1ecb57e (patch) | |
tree | 47bcbc7ea3dc16e8b350a8efd0c764037134f2ef /Lib/asyncio/futures.py | |
parent | 3e2078023175673b146e18fec2ad8d9ea3ffc20f (diff) | |
download | cpython-753c693708b34d559ff82a9a8fcb06c4e1ecb57e.tar.gz |
Rename Future._blocking to _asyncio_future_blocking.
This is now an official "protected" API that can be used to write
classes that are duck-type-compatible with Future without subclassing
it. (For that purpose I also changed isinstance(result, Future) to
check for this attribute instead.)
Hopefully Amber Brown can use this to make Twisted.Deferred compatible
with asyncio.Future.
Tests and docs are TBD.
Diffstat (limited to 'Lib/asyncio/futures.py')
-rw-r--r-- | Lib/asyncio/futures.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py index 1feba4d370..edc13dcc47 100644 --- a/Lib/asyncio/futures.py +++ b/Lib/asyncio/futures.py @@ -134,7 +134,15 @@ class Future: _loop = None _source_traceback = None - _blocking = False # proper use of future (yield vs yield from) + # This field is used for a dual purpose: + # - Its presence is a marker to declare that a class implements + # the Future protocol (i.e. is intended to be duck-type compatible). + # 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. + # `yield Future()` (incorrect). + _asyncio_future_blocking = False _log_traceback = False # Used for Python 3.4 and later _tb_logger = None # Used for Python 3.3 only @@ -357,7 +365,7 @@ class Future: def __iter__(self): if not self.done(): - self._blocking = True + self._asyncio_future_blocking = True yield self # This tells Task to wait for completion. assert self.done(), "yield from wasn't used with future" return self.result() # May raise too. |