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
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
1"""Useful internal functions."""
3from typing import Any, Callable, NoReturn, TypeVar
5from ._compat import TypeAlias
6from .errors import StructureHandlerNotFoundError
8T = TypeVar("T")
10Predicate: TypeAlias = Callable[[Any], bool]
11"""A predicate function determines if a type can be handled."""
14def identity(obj: T) -> T:
15 """The identity function."""
16 return obj
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)