Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Improve performance of asyncio.iscoroutine
  • Loading branch information
Yury Selivanov
Yury Selivanov committed Nov 9, 2016
commit 7e9a4d52c683e672b6a7c213d36846291e49a82f
8 changes: 8 additions & 0 deletions asyncio/coroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@

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:
Expand Down Expand Up @@ -255,6 +259,10 @@ def 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):
Expand Down