From 1c5ed8dddc72144cf79187adc87368ab2f0115e2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 25 Jul 2014 16:36:06 +0200 Subject: Catch SyntaxError when importing asyncio for convenience: ignore SyntaxError caused by "yield from" if tulip is in the Python path --- trollius/coroutines.py | 12 ++++-------- trollius/events.py | 4 +++- 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 -- cgit v1.2.1