compat.py 875 B

1234567891011121314151617181920212223242526272829303132
  1. try:
  2. from inspect import iscoroutine
  3. except ImportError:
  4. def iscoroutine(obj): # type: ignore
  5. return False
  6. try:
  7. from asyncio import Future, ensure_future # type: ignore
  8. except ImportError:
  9. class Future: # type: ignore
  10. def __init__(self):
  11. raise Exception("You need asyncio for using Futures")
  12. def set_result(self):
  13. raise Exception("You need asyncio for using Futures")
  14. def set_exception(self):
  15. raise Exception("You need asyncio for using Futures")
  16. def ensure_future(): # type: ignore
  17. raise Exception("ensure_future needs asyncio for executing")
  18. try:
  19. from .iterate_promise import iterate_promise
  20. except (SyntaxError, ImportError):
  21. def iterate_promise(promise): # type: ignore
  22. raise Exception('You need "yield from" syntax for iterate in a Promise.')