CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
_util.py30 linesDownload Raw Back to PIL
1from __future__ import annotations
2
3import os
4
5TYPE_CHECKING = False
6if TYPE_CHECKING:
7    from typing import Any, NoReturn, TypeGuard
8
9    from ._typing import StrOrBytesPath
10
11
12def is_path(f: Any) -> TypeGuard[StrOrBytesPath]:
13    return isinstance(f, (bytes, str, os.PathLike))
14
15
16class DeferredError:
17    def __init__(self, ex: BaseException):
18        self.ex = ex
19
20    def __getattr__(self, elt: str) -> NoReturn:
21        raise self.ex
22
23    @staticmethod
24    def new(ex: BaseException) -> Any:
25        """
26        Creates an object that raises the wrapped exception ``ex`` when used,
27        and casts it to :py:obj:`~typing.Any` type.
28        """
29        return DeferredError(ex)
30 
Aluode/PerceptionLabPortable · CoolFace