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_bool(x: bool, **kwargs) int[source]
pythonwrench.checksum.checksum_bytearray(x: bytearray, **kwargs) int[source]
pythonwrench.checksum.checksum_bytes(x: bytes, **kwargs) int[source]
pythonwrench.checksum.checksum_complex(x: complex, **kwargs) int[source]
pythonwrench.checksum.checksum_dataclass(x: DataclassInstance, **kwargs) int[source]
pythonwrench.checksum.checksum_date(x: date, **kwargs) int[source]
pythonwrench.checksum.checksum_datetime(x: datetime, **kwargs) int[source]
pythonwrench.checksum.checksum_dict(x: dict, **kwargs) int[source]
pythonwrench.checksum.checksum_enum(x: Enum, **kwargs) int[source]
pythonwrench.checksum.checksum_float(x: float, **kwargs) int[source]
pythonwrench.checksum.checksum_function(x: LambdaType, **kwargs) int[source]
pythonwrench.checksum.checksum_generator(x: Generator, **kwargs) int[source]
pythonwrench.checksum.checksum_int(x: int, **kwargs) int[source]
pythonwrench.checksum.checksum_list_tuple(x: list | tuple, **kwargs) int[source]
pythonwrench.checksum.checksum_method(x: MethodType, **kwargs) int[source]
pythonwrench.checksum.checksum_namedtuple(x: NamedTupleInstance, **kwargs) int[source]
pythonwrench.checksum.checksum_none(x: None, **kwargs) int[source]
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.checksum_partial(x: partial, **kwargs) int[source]
pythonwrench.checksum.checksum_path(x: Path, **kwargs) int[source]
pythonwrench.checksum.checksum_pattern(x: Pattern, **kwargs) int[source]
pythonwrench.checksum.checksum_range(x: range, **kwargs) int[source]
pythonwrench.checksum.checksum_set(x: set | frozenset, **kwargs) int[source]
pythonwrench.checksum.checksum_slice(x: slice, **kwargs) int[source]
pythonwrench.checksum.checksum_str(x: str, **kwargs) int[source]
pythonwrench.checksum.checksum_type(x: type, **kwargs) int[source]
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.