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

Commit 7e9a4d5

Browse files
committed
Improve performance of asyncio.iscoroutine
1 parent ea776a1 commit 7e9a4d5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

asyncio/coroutines.py

+8
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@
3333

3434
try:
3535
_types_coroutine = types.coroutine
36+
_types_CoroutineType = types.CoroutineType
3637
except AttributeError:
38+
# Python 3.4
3739
_types_coroutine = None
40+
_types_CoroutineType = None
3841

3942
try:
4043
_inspect_iscoroutinefunction = inspect.iscoroutinefunction
4144
except AttributeError:
45+
# Python 3.4
4246
_inspect_iscoroutinefunction = lambda func: False
4347

4448
try:
@@ -255,6 +259,10 @@ def iscoroutinefunction(func):
255259
_COROUTINE_TYPES = (types.GeneratorType, CoroWrapper)
256260
if _CoroutineABC is not None:
257261
_COROUTINE_TYPES += (_CoroutineABC,)
262+
if _types_CoroutineType is not None:
263+
# Prioritize native coroutine check to speed-up
264+
# asyncio.iscoroutine.
265+
_COROUTINE_TYPES = (_types_CoroutineType,) + _COROUTINE_TYPES
258266

259267

260268
def iscoroutine(obj):

0 commit comments

Comments
 (0)