baybe.utils.basic.match_attributes¶
- baybe.utils.basic.match_attributes(object: Any, callable_: Callable, /, strict: bool = True, ignore: Collection[str] = ())[source]¶
Find the attributes of an object that match with a given callable signature.
Parameters appearing in the callable signature that have no match with the given object attributes are ignored.
- Parameters:
object (
Any
) – The object whose attributes are to be matched.callable – The callable against whose signature the attributes are to be matched.
strict (
bool
) – IfTrue
, an error is raised when the object has attributes that are not found in the callable signature (see alsoignore
). IfFalse
, these attributes are returned separately.ignore (
Collection
[str
]) – A collection of attributes names that are to be ignored during matching.
- Raises:
ValueError – If applied to a non-attrs object.
UnmatchedAttributeError – In strict mode, if not all attributes can be matched.
- Return type:
- Returns:
A dictionary mapping the matched attribute names to their values.
A dictionary mapping the unmatched attribute names to their values.