[Python-checkins] cpython (merge 3.6 -> default): Merge 3.6 (issue #28634)
yury.selivanov
python-checkins at python.org
Mon Nov 7 16:08:03 EST 2016
https://hg.python.org/cpython/rev/44c1ec7689e5
changeset: 104954:44c1ec7689e5
parent: 104951:573bc1f9900e
parent: 104953:a02915e4c165
user: Yury Selivanov <yury at magic.io>
date: Mon Nov 07 16:07:58 2016 -0500
summary:
Merge 3.6 (issue #28634)
files:
Lib/asyncio/base_futures.py | 3 +-
Lib/test/test_asyncio/test_futures.py | 23 +++++++++++++++
2 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/Lib/asyncio/base_futures.py b/Lib/asyncio/base_futures.py
--- a/Lib/asyncio/base_futures.py
+++ b/Lib/asyncio/base_futures.py
@@ -27,7 +27,8 @@
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
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -105,6 +105,29 @@
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())
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list