Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Commit ae82bb7

Browse files
committed
Fix isfuture() to support Mock(asyncio.Future)
Fixes #454.
1 parent 26d01d7 commit ae82bb7

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

asyncio/futures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def isfuture(obj):
117117
itself as duck-type compatible by setting _asyncio_future_blocking.
118118
See comment in Future for more details.
119119
"""
120-
return (hasattr(type(obj), '_asyncio_future_blocking') and
120+
return (hasattr(obj.__class__, '_asyncio_future_blocking') and
121121
obj._asyncio_future_blocking is not None)
122122

123123

tests/test_futures.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,13 @@ def __init__(self):
113113

114114
self.assertFalse(asyncio.isfuture(1))
115115
self.assertFalse(asyncio.isfuture(asyncio.Future))
116+
117+
# As `isinstance(Mock(), Future)` returns `False`
116118
self.assertFalse(asyncio.isfuture(mock.Mock()))
117119

120+
# As `isinstance(Mock(Future), Future)` returns `True`
121+
self.assertTrue(asyncio.isfuture(mock.Mock(asyncio.Future)))
122+
118123
f = asyncio.Future(loop=self.loop)
119124
self.assertTrue(asyncio.isfuture(f))
120125
f.cancel()

0 commit comments

Comments
 (0)