Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/cattrs/fns.py: 67%

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

12 statements  

1"""Useful internal functions.""" 

2 

3from typing import Any, Callable, NoReturn, TypeVar 

4 

5from ._compat import TypeAlias 

6from .errors import StructureHandlerNotFoundError 

7 

8T = TypeVar("T") 

9 

10Predicate: TypeAlias = Callable[[Any], bool] 

11"""A predicate function determines if a type can be handled.""" 

12 

13 

14def identity(obj: T) -> T: 

15 """The identity function.""" 

16 return obj 

17 

18 

19def raise_error(_, cl: Any) -> NoReturn: 

20 """At the bottom of the condition stack, we explode if we can't handle it.""" 

21 msg = f"Unsupported type: {cl!r}. Register a structure hook for it." 

22 raise StructureHandlerNotFoundError(msg, type_=cl)