_util.py 635 B

1234567891011121314151617181920212223242526
  1. from __future__ import annotations
  2. import os
  3. from typing import Any, NoReturn
  4. from ._typing import StrOrBytesPath, TypeGuard
  5. def is_path(f: Any) -> TypeGuard[StrOrBytesPath]:
  6. return isinstance(f, (bytes, str, os.PathLike))
  7. class DeferredError:
  8. def __init__(self, ex: BaseException):
  9. self.ex = ex
  10. def __getattr__(self, elt: str) -> NoReturn:
  11. raise self.ex
  12. @staticmethod
  13. def new(ex: BaseException) -> Any:
  14. """
  15. Creates an object that raises the wrapped exception ``ex`` when used,
  16. and casts it to :py:obj:`~typing.Any` type.
  17. """
  18. return DeferredError(ex)