summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/coroutines.py
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-11-15 20:21:07 (GMT)
committerYury Selivanov <yury@magic.io>2016-11-15 20:21:07 (GMT)
commit27182bb23229b61edbb40bd321cfdc183065afc4 (patch)
tree815c15129a304401ded35e1f125b93b00a6ed478 /Lib/asyncio/coroutines.py
parent63859aea9b413a3b44ad3c19d750d4a55fae7864 (diff)
parent0ed20cdfb723c68d604eddec0fc66436ce18e9c0 (diff)
downloadcpython-27182bb23229b61edbb40bd321cfdc183065afc4.zip
cpython-27182bb23229b61edbb40bd321cfdc183065afc4.tar.gz
cpython-27182bb23229b61edbb40bd321cfdc183065afc4.tar.bz2
Merge 3.5 (issue #28703)
Diffstat (limited to 'Lib/asyncio/coroutines.py')
-rw-r--r--Lib/asyncio/coroutines.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py
index 2fc76ad..08e9441 100644
--- a/Lib/asyncio/coroutines.py
+++ b/Lib/asyncio/coroutines.py
@@ -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 = True # For iscoroutinefunction().
+ wrapper._is_coroutine = _is_coroutine # 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):