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 22
33__all__ = ['CancelledError' , 'TimeoutError' ,
44 'InvalidStateError' ,
5- 'Future' , 'wrap_future' ,
5+ 'Future' , 'wrap_future' , 'isfuture' ,
66 ]
77
88import concurrent .futures ._base
@@ -117,7 +117,8 @@ 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 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 )
121122
122123
123124class Future :
Original file line number Diff line number Diff line change @@ -101,6 +101,24 @@ def setUp(self):
101101 self .loop = self .new_test_loop ()
102102 self .addCleanup (self .loop .close )
103103
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+
104122 def test_initial_state (self ):
105123 f = asyncio .Future (loop = self .loop )
106124 self .assertFalse (f .cancelled ())
You can’t perform that action at this time.
0 commit comments