Skip to content

arguments

arguments #

argument_hash — a call's argument hashes as its value, a failure naming the parameter.

UnhashableArgumentError #

Bases: TypeError

A recipe argument whose type has no canonical content hash.

Source code in capturegraph-lib/capturegraph/scratch/values/arguments.py
class UnhashableArgumentError(TypeError):
    """A recipe argument whose type has no canonical content hash."""

    def __init__(self, param_name: str, value_type: type) -> None:
        """The error for ``param_name`` holding a ``value_type`` value."""
        super().__init__(
            f"Argument {param_name!r} of type {value_type.__name__} cannot be hashed for "
            f"memoization. Pass a CGType value or a plain int/float/bool/str/bytes/None, "
            f"datetime/date/timedelta, or a tuple/list/dict/frozenset of those."
        )
        self.param_name = param_name
        self.value_type = value_type

__init__(param_name, value_type) #

The error for param_name holding a value_type value.

Source code in capturegraph-lib/capturegraph/scratch/values/arguments.py
def __init__(self, param_name: str, value_type: type) -> None:
    """The error for ``param_name`` holding a ``value_type`` value."""
    super().__init__(
        f"Argument {param_name!r} of type {value_type.__name__} cannot be hashed for "
        f"memoization. Pass a CGType value or a plain int/float/bool/str/bytes/None, "
        f"datetime/date/timedelta, or a tuple/list/dict/frozenset of those."
    )
    self.param_name = param_name
    self.value_type = value_type

argument_hash(param_name, value) #

The content hash identifying value as the argument to param_name.

Parameters:

Name Type Description Default
param_name str

The parameter the value is bound to.

required
value object

The argument value.

required

Raises:

Type Description
UnhashableArgumentError

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

Source code in capturegraph-lib/capturegraph/scratch/values/arguments.py
def argument_hash(param_name: str, value: object) -> ContentHash:
    """The content hash identifying ``value`` as the argument to ``param_name``.

    Args:
        param_name: The parameter the value is bound to.
        value: The argument value.

    Raises:
        UnhashableArgumentError: If ``value``, or anything nested in it, has no encoder.
    """
    try:
        return value_hash(value)
    except NoEncoder as error:
        raise UnhashableArgumentError(param_name, error.value_type) from None