diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-07-25 16:36:06 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-07-25 16:36:06 +0200 |
commit | 1c5ed8dddc72144cf79187adc87368ab2f0115e2 (patch) | |
tree | ed757cfa52d93e5f5cad0bc5e6bdc17b1fd6fed8 | |
parent | 36200ec6a535c72dcad083702809a6bbe5ccab42 (diff) | |
download | trollius-1c5ed8dddc72144cf79187adc87368ab2f0115e2.tar.gz |
Catch SyntaxError when importing asyncio for convenience: ignore SyntaxError
caused by "yield from" if tulip is in the Python path
-rw-r--r-- | trollius/coroutines.py | 12 | ||||
-rw-r--r-- | trollius/events.py | 4 | ||||
-rw-r--r-- | trollius/futures.py | 8 |
3 files changed, 9 insertions, 15 deletions
diff --git a/trollius/coroutines.py b/trollius/coroutines.py index 5c11be2..1c842fb 100644 --- a/trollius/coroutines.py +++ b/trollius/coroutines.py @@ -8,10 +8,6 @@ import os import sys import traceback import types -try: - import asyncio -except ImportError: - asyncio = None from . import compat from . import events @@ -281,13 +277,13 @@ def iscoroutinefunction(func): _COROUTINE_TYPES = (types.GeneratorType, CoroWrapper) -if asyncio is not None: +if events.asyncio is not None: # Accept also asyncio CoroWrapper for interoperability - if hasattr(asyncio, 'coroutines'): - _COROUTINE_TYPES += (asyncio.coroutines.CoroWrapper,) + if hasattr(events.asyncio, 'coroutines'): + _COROUTINE_TYPES += (events.asyncio.coroutines.CoroWrapper,) else: # old Tulip/Python versions - _COROUTINE_TYPES += (asyncio.tasks.CoroWrapper,) + _COROUTINE_TYPES += (events.asyncio.tasks.CoroWrapper,) def iscoroutine(obj): """Return True if obj is a coroutine object.""" diff --git a/trollius/events.py b/trollius/events.py index 7fa658d..131399b 100644 --- a/trollius/events.py +++ b/trollius/events.py @@ -19,7 +19,9 @@ import sys from trollius import compat try: import asyncio -except ImportError: +except (ImportError, SyntaxError): + # ignore SyntaxError for convenience: ignore SyntaxError caused by "yield + # from" if asyncio module is in the Python path asyncio = None diff --git a/trollius/futures.py b/trollius/futures.py index 45bb18d..fa0a7e7 100644 --- a/trollius/futures.py +++ b/trollius/futures.py @@ -8,10 +8,6 @@ __all__ = ['CancelledError', 'TimeoutError', import logging import sys import traceback -try: - import asyncio -except ImportError: - asyncio = None from . import events from . import executor @@ -393,9 +389,9 @@ class Future(object): result = other.result() self.set_result(result) -if asyncio is not None: +if events.asyncio is not None: # Accept also asyncio Future objects for interoperability - _FUTURE_CLASSES = (Future, asyncio.Future) + _FUTURE_CLASSES = (Future, events.asyncio.Future) else: _FUTURE_CLASSES = Future |