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
d0965de0
Commit
d0965de0
authored
Nov 15, 2016
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28703: Fix asyncio.iscoroutinefunction to handle Mock objects.
parent
e09ca3c3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
2 deletions
+18
-2
Lib/asyncio/coroutines.py
Lib/asyncio/coroutines.py
+14
-2
Lib/test/test_asyncio/test_tasks.py
Lib/test/test_asyncio/test_tasks.py
+2
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/asyncio/coroutines.py
View file @
d0965de0
...
...
@@ -33,12 +33,16 @@ _DEBUG = (not sys.flags.ignore_environment and
try
:
_types_coroutine
=
types
.
coroutine
_types_CoroutineType
=
types
.
CoroutineType
except
AttributeError
:
# Python 3.4
_types_coroutine
=
None
_types_CoroutineType
=
None
try
:
_inspect_iscoroutinefunction
=
inspect
.
iscoroutinefunction
except
AttributeError
:
# Python 3.4
_inspect_iscoroutinefunction
=
lambda
func
:
False
try
:
...
...
@@ -238,19 +242,27 @@ def coroutine(func):
w
.
__qualname__
=
getattr
(
func
,
'__qualname__'
,
None
)
return
w
wrapper
.
_is_coroutine
=
Tru
e
# For iscoroutinefunction().
wrapper
.
_is_coroutine
=
_is_coroutin
e
# For iscoroutinefunction().
return
wrapper
# A marker for iscoroutinefunction.
_is_coroutine
=
object
()
def
iscoroutinefunction
(
func
):
"""Return True if func is a decorated coroutine function."""
return
(
getattr
(
func
,
'_is_coroutine'
,
False
)
or
return
(
getattr
(
func
,
'_is_coroutine'
,
None
)
is
_is_coroutine
or
_inspect_iscoroutinefunction
(
func
))
_COROUTINE_TYPES
=
(
types
.
GeneratorType
,
CoroWrapper
)
if
_CoroutineABC
is
not
None
:
_COROUTINE_TYPES
+=
(
_CoroutineABC
,)
if
_types_CoroutineType
is
not
None
:
# Prioritize native coroutine check to speed-up
# asyncio.iscoroutine.
_COROUTINE_TYPES
=
(
_types_CoroutineType
,)
+
_COROUTINE_TYPES
def
iscoroutine
(
obj
):
...
...
Lib/test/test_asyncio/test_tasks.py
View file @
d0965de0
...
...
@@ -1376,6 +1376,8 @@ class TaskTests(test_utils.TestCase):
yield
self
.
assertTrue
(
asyncio
.
iscoroutinefunction
(
fn2
))
self
.
assertFalse
(
asyncio
.
iscoroutinefunction
(
mock
.
Mock
()))
def
test_yield_vs_yield_from
(
self
):
fut
=
asyncio
.
Future
(
loop
=
self
.
loop
)
...
...
Misc/NEWS
View file @
d0965de0
...
...
@@ -465,6 +465,8 @@ Library
- Issue #28653: Fix a refleak in functools.lru_cache.
- Issue #28703: Fix asyncio.iscoroutinefunction to handle Mock objects.
IDLE
----
...
...
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