Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7b7bd1fd
Commit
7b7bd1fd
authored
Nov 07, 2016
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28634: Fix asyncio.isfuture() to support mocks
parent
3de3e4a5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
Lib/asyncio/futures.py
Lib/asyncio/futures.py
+3
-2
Lib/test/test_asyncio/test_futures.py
Lib/test/test_asyncio/test_futures.py
+23
-0
No files found.
Lib/asyncio/futures.py
View file @
7b7bd1fd
...
...
@@ -2,7 +2,7 @@
__all__
=
[
'CancelledError'
,
'TimeoutError'
,
'InvalidStateError'
,
'Future'
,
'wrap_future'
,
'Future'
,
'wrap_future'
,
'isfuture'
,
]
import
concurrent.futures._base
...
...
@@ -117,7 +117,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
)
class
Future
:
...
...
Lib/test/test_asyncio/test_futures.py
View file @
7b7bd1fd
...
...
@@ -101,6 +101,29 @@ class FutureTests(test_utils.TestCase):
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
))
self
.
assertFalse
(
asyncio
.
isfuture
(
asyncio
.
Future
))
# As `isinstance(Mock(), Future)` returns `False`
self
.
assertFalse
(
asyncio
.
isfuture
(
mock
.
Mock
()))
# As `isinstance(Mock(Future), Future)` returns `True`
self
.
assertTrue
(
asyncio
.
isfuture
(
mock
.
Mock
(
asyncio
.
Future
)))
f
=
asyncio
.
Future
(
loop
=
self
.
loop
)
self
.
assertTrue
(
asyncio
.
isfuture
(
f
))
f
.
cancel
()
def
test_initial_state
(
self
):
f
=
asyncio
.
Future
(
loop
=
self
.
loop
)
self
.
assertFalse
(
f
.
cancelled
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment