Skip to content

plain

plain #

How a plain Python value encodes: tagged canonical bytes, one registered encoder per type.

NoEncoder #

Bases: TypeError

A value, or something nested in it, with no canonical encoding.

Source code in capturegraph-lib/capturegraph/scratch/values/plain.py
class NoEncoder(TypeError):
    """A value, or something nested in it, with no canonical encoding."""

    def __init__(self, value_type: type) -> None:
        """The error for a value of ``value_type``."""
        super().__init__(f"{value_type.__name__} has no content hash")
        self.value_type = value_type

__init__(value_type) #

The error for a value of value_type.

Source code in capturegraph-lib/capturegraph/scratch/values/plain.py
def __init__(self, value_type: type) -> None:
    """The error for a value of ``value_type``."""
    super().__init__(f"{value_type.__name__} has no content hash")
    self.value_type = value_type

canonical(value) #

The tagged canonical bytes of a plain value.

Register an encoder for a new plain type with @canonical.register; value_hash registers every value it walks, which encodes as its hash.

Raises:

Type Description
NoEncoder

If value, or anything nested in it, has no encoder.

Source code in capturegraph-lib/capturegraph/scratch/values/plain.py
@singledispatch
def canonical(value: object) -> bytes:
    """The tagged canonical bytes of a plain value.

    Register an encoder for a new plain type with ``@canonical.register``;
    ``value_hash`` registers every value it walks, which encodes as its hash.

    Raises:
        NoEncoder: If ``value``, or anything nested in it, has no encoder.
    """
    raise NoEncoder(type(value))