fleche.call

Attributes

AnyCall

Classes

Ignored

Type wrapper to mark a function argument as ignored for caching.

Required

Type wrapper to mark a function argument as required for caching.

FunctionProfile

All static per-function metadata, cached once per callable.

Call

Represents a function call, capturing its name, arguments, and keyword arguments.

DigestedCall

A Call where arguments and result are Digest pointers into a value store.

LazyCall

QueryCall

Functions

bind(func, args, kwargs[, apply_defaults, partial])

Thin wrapper around inspect.Signature.bind() / bind_partial().

Module Contents

class fleche.call.Ignored[source]

Type wrapper to mark a function argument as ignored for caching.

Can be used as a type hint: arg: fleche.Ignored or arg: fleche.Ignored[int].

classmethod __class_getitem__(item)[source]
class fleche.call.Required[source]

Type wrapper to mark a function argument as required for caching.

Arguments marked as required must be explicitly provided by the caller as keyword arguments (i.e. not via their default value) for the result to be cached. This is useful for arguments like random seeds or iteration counts, where using the default value might lead to non-deterministic or otherwise undesirable caching behavior.

This is mainly useful when wrapping third-party functions where you do not control the default arguments.

Can be used as a type hint: arg: fleche.Required or arg: fleche.Required[int].

classmethod __class_getitem__(item)[source]
class fleche.call.FunctionProfile[source]

All static per-function metadata, cached once per callable.

signature: inspect.Signature[source]
qualname: str[source]
module: str[source]
version: str | int | None[source]
code_digest: fleche.digest.Digest | None[source]
ignored: frozenset[str][source]
required: frozenset[str][source]
classmethod of(func) FunctionProfile[source]

Compute a FunctionProfile for func without caching.

strip_for_key(bound: dict) None[source]

Remove ignored arguments from a bound arguments dict in-place.

check_required(args: tuple, kwargs: dict) list[str][source]

Return names of required args not explicitly provided as keyword arguments.

fleche.call.bind(func, args, kwargs, apply_defaults=False, partial=False)[source]

Thin wrapper around inspect.Signature.bind() / bind_partial().

Parameters:
  • func – The callable whose signature to bind against.

  • args – Positional arguments.

  • kwargs – Keyword arguments.

  • apply_defaults – If True, fill in default values for parameters that were not explicitly supplied.

  • partial – If True, use bind_partial(), which allows required arguments to be omitted (treated as wildcards).

Returns:

inspect.BoundArguments.arguments — an OrderedDict containing the supplied (and, when requested, defaulted) values.

class fleche.call.Call[source]

Represents a function call, capturing its name, arguments, and keyword arguments.

module and version can be optionally set to be included in the hash of the call. version should be a plain integer and monotonically increase. Each different version will completely change the hash of the call, invalidating previously cached results.

name: str[source]
arguments: dict[str, Any][source]
metadata: dict[str, dict[str, Any]][source]
module: str | None = None[source]
version: str | int | None = None[source]
code_digest: str | None = None[source]
result: Any = None[source]
classmethod from_call(func, *args, **kwargs)[source]
to_lookup_key() fleche.digest.Digest[source]
_to_digested(save_fn: Callable[[Any], fleche.digest.Digest]) DigestedCall[source]

Generic conversion to DigestedCall using save_fn to handle each value.

stash(values) DigestedCall[source]

Save arguments and result into values, returning a DigestedCall.

Result save errors propagate to the caller. Argument save errors fall back to a digest-only reference (the value is hashed but not stored).

Parameters:

values – A ValueStorage instance to persist values into.

Returns:

A DigestedCall with all argument values and the result replaced by their Digest keys.

See also

digest() for a variant that does not write to storage.

digest() DigestedCall[source]

Digest arguments and result without saving to storage, returning a DigestedCall.

Equivalent to stash() but uses digest() instead of values.save, so no data is written anywhere.

class fleche.call.DigestedCall[source]

A Call where arguments and result are Digest pointers into a value store.

Produced by Call.stash() or Call.digest(); represents a call whose values have been replaced by their content-addressed keys.

name: str[source]
arguments: dict[str, fleche.digest.Digest][source]
result: fleche.digest.Digest | None = None[source]
metadata: dict[str, dict[str, Any]][source]
module: str | None = None[source]
version: str | int | None = None[source]
code_digest: str | None = None[source]
__eq__(other: object) bool[source]
__digest__()[source]
to_lookup_key() fleche.digest.Digest[source]
fetch(cache) LazyCall[source]

Wrap this DigestedCall in a LazyCall backed by cache.

Parameters:

cache – A cache instance (e.g. Cache) whose value storage will be used to load argument and result values on demand.

Returns:

A LazyCall that loads values lazily from cache.

class fleche.call.LazyCall[source]
name: str[source]
_arguments: dict[str, Any][source]
_result: Any[source]
_cache: Any[source]
metadata: dict[str, dict[str, Any]][source]
module: str | None = None[source]
version: str | int | None = None[source]
code_digest: str | None = None[source]
property arguments[source]
property result[source]
to_lookup_key() str[source]
fetch() Call[source]

Reconstruct a full Call object by loading all values from the cache.

detach() DigestedCall[source]

Return the cache-free DigestedCall shadow of this LazyCall.

The inverse of DigestedCall.fetch(): strips the _cache reference so the result can cross process boundaries (e.g. over the wire in fleche.remote) without carrying a live cache pointer.

__digest__()[source]
class fleche.call.QueryCall[source]
name: StrQueryType = None[source]
arguments: dict[str, AnyQueryType] | None = None[source]
metadata: dict[str, dict[str, StrQueryType]] | None = None[source]
module: str | None = None[source]
version: str | int | None = None[source]
code_digest: fleche.digest.Digest | None = None[source]
result: AnyQueryType = None[source]
classmethod from_call(func, *args, **kwargs)[source]
matches(other: Call | LazyCall | DigestedCall) bool[source]

Check if this call matches another call, treating None as a wildcard in this object.

fleche.call.AnyCall[source]