pythonwrench.checksum module¶
- pythonwrench.checksum.checksum_any(x: ~typing.Any, *, isinstance_fn: ~typing.Callable[[~typing.Any, type | tuple], bool] = <built-in function isinstance>, **kwargs) int[source]¶
Compute checksum integer value from an arbitrary object.
Supports most builtin types. Checksum can be used to compare objects. Not meant for security/cryptography.
- pythonwrench.checksum.checksum_object(x: ~typing.Any, *, isinstance_fn: ~typing.Callable[[~typing.Any, type | tuple], bool] = <built-in function isinstance>, **kwargs) int[source]¶
Compute checksum integer value from an arbitrary object.
Supports most builtin types. Checksum can be used to compare objects. Not meant for security/cryptography.
-
pythonwrench.checksum.register_checksum_fn(class_or_tuple: type | tuple[type, ...], *, custom_predicate: None =
None, priority: int =0) Callable[source]¶ -
pythonwrench.checksum.register_checksum_fn(class_or_tuple: None =
None, *, custom_predicate: Predicate, priority: int =0) Callable Decorator to add a checksum function.
Example¶
>>> import numpy as np >>> @register_checksum_fn(np.ndarray) >>> def my_checksum_for_numpy(x: np.ndarray): >>> return int(x.sum()) >>> pw.checksum_any(np.array([1, 2])) # calls my_checksum_for_numpy internally, even if array in nested inside a list, dict, etc.