summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-11-07 21:07:58 (GMT)
committerYury Selivanov <yury@magic.io>2016-11-07 21:07:58 (GMT)
commit884edfcc83ec064300a9fb7bde7fece5920e670d (patch)
tree16caa86be0edb4f4563e534e40496eb4996f47d9
parentabbbb88dc780f3cb976f581b0b963cee53f542f2 (diff)
parent6130c0271f00e54fe754f764733668ecda617d51 (diff)
downloadcpython-884edfcc83ec064300a9fb7bde7fece5920e670d.zip
cpython-884edfcc83ec064300a9fb7bde7fece5920e670d.tar.gz
cpython-884edfcc83ec064300a9fb7bde7fece5920e670d.tar.bz2
Merge 3.6 (issue #28634)
-rw-r--r--Lib/asyncio/base_futures.py3
-rw-r--r--Lib/test/test_asyncio/test_futures.py23
2 files changed, 25 insertions, 1 deletions
diff --git a/Lib/asyncio/base_futures.py b/Lib/asyncio/base_futures.py
index 64f7845..01259a0 100644
--- a/Lib/asyncio/base_futures.py
+++ b/Lib/asyncio/base_futures.py
@@ -27,7 +27,8 @@ def isfuture(obj):
itself as duck-type compatible by setting _asyncio_future_blocking.
See comment in Future for more details.
"""
- return getattr(obj, '_asyncio_future_blocking', None) is not None
+ return (hasattr(obj.__class__, '_asyncio_future_blocking') and
+ obj._asyncio_future_blocking is not None)
def _format_callbacks(cb):
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
index fd4d261..c147608 100644
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -105,6 +105,29 @@ class BaseFutureTests:
self.loop = self.new_test_loop()
self.addCleanup(self.loop.close)
+ def test_isfuture(self):
+ class MyFuture:
+ _asyncio_future_blocking = None
+
+ def __init__(self):
+ self._asyncio_future_blocking = False
+
+ self.assertFalse(asyncio.isfuture(MyFuture))
+ self.assertTrue(asyncio.isfuture(MyFuture()))
+ self.assertFalse(asyncio.isfuture(1))
+
+ # As `isinstance(Mock(), Future)` returns `False`
+ self.assertFalse(asyncio.isfuture(mock.Mock()))
+
+ f = self._new_future(loop=self.loop)
+ self.assertTrue(asyncio.isfuture(f))
+ self.assertFalse(asyncio.isfuture(type(f)))
+
+ # As `isinstance(Mock(Future), Future)` returns `True`
+ self.assertTrue(asyncio.isfuture(mock.Mock(type(f))))
+
+ f.cancel()
+
def test_initial_state(self):
f = self._new_future(loop=self.loop)
self.assertFalse(f.cancelled())