summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-11 18:09:54 +0200
committerVictor Stinner <victor.stinner@gmail.com>2014-06-11 18:09:54 +0200
commit1fcf2ceb619af1353bcf58c967dd30eabbd86c98 (patch)
treece0df7a142aa15cc67948fd7d0bcd7d44b977790
parent827421b2b8a4bed339a5d766db7c0e286e08238a (diff)
downloadtrollius-1fcf2ceb619af1353bcf58c967dd30eabbd86c98.tar.gz
iscoroutine() now also supports asyncio.CoroWrapper
-rw-r--r--trollius/coroutines.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/trollius/coroutines.py b/trollius/coroutines.py
index ee610c2..fd16ceb 100644
--- a/trollius/coroutines.py
+++ b/trollius/coroutines.py
@@ -149,9 +149,16 @@ def iscoroutinefunction(func):
return getattr(func, '_is_coroutine', False)
+if asyncio is not None:
+ # Accept also asyncio Future objects for interoperability
+ _COROUTINE_TYPES = (CoroWrapper, asyncio.tasks.CoroWrapper)
+else:
+ _COROUTINE_TYPES = CoroWrapper
+
+
def iscoroutine(obj):
"""Return True if obj is a coroutine object."""
- return isinstance(obj, CoroWrapper) or inspect.isgenerator(obj)
+ return isinstance(obj, _COROUTINE_TYPES) or inspect.isgenerator(obj)
class FromWrapper(object):
__slots__ = ('obj',)