compat.py 739 B

1234567891011121314151617181920212223
  1. """Utilities for providing backward compatibility."""
  2. from pip._vendor import six
  3. def get_exc_info_from_future(future):
  4. """
  5. Get an exc_info value from a Future.
  6. Given a a Future instance, retrieve an exc_info value suitable for passing
  7. in as the exc_info parameter to logging.Logger.log() and related methods.
  8. On Python 2, this will be a (type, value, traceback) triple.
  9. On Python 3, this will be an exception instance (with embedded traceback).
  10. If there was no exception, None is returned on both versions of Python.
  11. """
  12. if six.PY3:
  13. return future.exception()
  14. else:
  15. ex, tb = future.exception_info()
  16. if ex is None:
  17. return None
  18. return type(ex), ex, tb