This repository was archived by the owner on Nov 23, 2017. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
__all__ = ['CancelledError' , 'TimeoutError' ,
4
4
'InvalidStateError' ,
5
- 'Future' , 'wrap_future' ,
5
+ 'Future' , 'wrap_future' , 'isfuture' ,
6
6
]
7
7
8
8
import concurrent .futures ._base
@@ -117,7 +117,8 @@ def isfuture(obj):
117
117
itself as duck-type compatible by setting _asyncio_future_blocking.
118
118
See comment in Future for more details.
119
119
"""
120
- return getattr (obj , '_asyncio_future_blocking' , None ) is not None
120
+ return (hasattr (type (obj ), '_asyncio_future_blocking' ) and
121
+ obj ._asyncio_future_blocking is not None )
121
122
122
123
123
124
class Future :
Original file line number Diff line number Diff line change @@ -101,6 +101,24 @@ def setUp(self):
101
101
self .loop = self .new_test_loop ()
102
102
self .addCleanup (self .loop .close )
103
103
104
+ def test_isfuture (self ):
105
+ class MyFuture :
106
+ _asyncio_future_blocking = None
107
+
108
+ def __init__ (self ):
109
+ self ._asyncio_future_blocking = False
110
+
111
+ self .assertFalse (asyncio .isfuture (MyFuture ))
112
+ self .assertTrue (asyncio .isfuture (MyFuture ()))
113
+
114
+ self .assertFalse (asyncio .isfuture (1 ))
115
+ self .assertFalse (asyncio .isfuture (asyncio .Future ))
116
+ self .assertFalse (asyncio .isfuture (mock .Mock ()))
117
+
118
+ f = asyncio .Future (loop = self .loop )
119
+ self .assertTrue (asyncio .isfuture (f ))
120
+ f .cancel ()
121
+
104
122
def test_initial_state (self ):
105
123
f = asyncio .Future (loop = self .loop )
106
124
self .assertFalse (f .cancelled ())
You can’t perform that action at this time.
0 commit comments