diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-06-11 18:09:54 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-06-11 18:09:54 +0200 |
commit | 1fcf2ceb619af1353bcf58c967dd30eabbd86c98 (patch) | |
tree | ce0df7a142aa15cc67948fd7d0bcd7d44b977790 | |
parent | 827421b2b8a4bed339a5d766db7c0e286e08238a (diff) | |
download | trollius-1fcf2ceb619af1353bcf58c967dd30eabbd86c98.tar.gz |
iscoroutine() now also supports asyncio.CoroWrapper
-rw-r--r-- | trollius/coroutines.py | 9 |
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',) |