Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pillow-10.4.0-py3.8-linux-x86_64.egg/PIL/_util.py: 75%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

16 statements  

1from __future__ import annotations 

2 

3import os 

4from typing import Any, NoReturn 

5 

6from ._typing import StrOrBytesPath, TypeGuard 

7 

8 

9def is_path(f: Any) -> TypeGuard[StrOrBytesPath]: 

10 return isinstance(f, (bytes, str, os.PathLike)) 

11 

12 

13def is_directory(f: Any) -> TypeGuard[StrOrBytesPath]: 

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

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

16 

17 

18class DeferredError: 

19 def __init__(self, ex: BaseException): 

20 self.ex = ex 

21 

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

23 raise self.ex 

24 

25 @staticmethod 

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

27 """ 

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

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

30 """ 

31 return DeferredError(ex)