Coverage for /usr/lib/python3/dist-packages/PIL/_util.py: 71%

17 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2025-06-14 15:25 +0200

1from __future__ import annotations 

2 

3import os 

4from pathlib import Path 

5from typing import Any, NoReturn 

6 

7from ._typing import TypeGuard 

8 

9 

10def is_path(f: Any) -> TypeGuard[bytes | str | Path]: 

11 return isinstance(f, (bytes, str, Path)) 

12 

13 

14def is_directory(f: Any) -> TypeGuard[bytes | str | Path]: 

15 """Checks if an object is a string, and that it points to a directory.""" 

16 return is_path(f) and os.path.isdir(f) 

17 

18 

19class DeferredError: 

20 def __init__(self, ex: BaseException): 

21 self.ex = ex 

22 

23 def __getattr__(self, elt: str) -> NoReturn: 

24 raise self.ex 

25 

26 @staticmethod 

27 def new(ex: BaseException) -> Any: 

28 """ 

29 Creates an object that raises the wrapped exception ``ex`` when used, 

30 and casts it to :py:obj:`~typing.Any` type. 

31 """ 

32 return DeferredError(ex)