hydra.overlay.python.util package

Submodules

Module contents

Internal collection classes and utilities for Hydra-Python.

Mirrors Hydra-Java’s hydra.util package. Persistent (structurally-shared) collection classes that satisfy collections.abc.{Sequence, Mapping, Set} so they can be used wherever the abstract types are accepted, while providing sub-linear updates suitable for inference-style workloads.

class hydra.overlay.python.util.ConsList(_inner: tuple[Any, ...] | None = None, _start: int = 0, *, _internal: bool = False)

Bases: Sequence[T], Generic[T]

A persistent (immutable) sequence backed by a native tuple plus offset.

Construct via ConsList.empty(), ConsList.cons(x, xs), ConsList.singleton(x), ConsList.of(...), or ConsList.from_iterable(...). Direct __init__ is gated.

concat(other: ConsList[T]) ConsList[T]
static cons(value: T, tail: ConsList[T]) ConsList[T]
drop(n: int) ConsList[T]
static empty() ConsList[Any]
filter(predicate: Callable[[T], bool]) ConsList[T]
foldl(f: Callable[[R, T], R], initial: R) R
foldr(f: Callable[[T, R], R], initial: R) R
static from_iterable(values: Iterable[T]) ConsList[T]
property head: T
init() ConsList[T]
is_empty() bool
last() T
map(f: Callable[[T], U]) ConsList[U]
static of(*elements: T) ConsList[T]
reverse() ConsList[T]
static singleton(value: T) ConsList[T]
property tail: ConsList[T]
take(n: int) ConsList[T]
class hydra.overlay.python.util.Lazy(fn: Callable[[], T])

Bases: Generic[T]

A one-shot memoizer for a zero-argument computation.

get() T
class hydra.overlay.python.util.PersistentMap(_inner: dict[Any, Any] | None = None, *, _internal: bool = False)

Bases: Mapping[K, V], Generic[K, V]

A persistent (immutable) map backed by a frozen native dict.

Construct via PersistentMap.empty(), PersistentMap.singleton(k, v), PersistentMap.from_pairs(...), or PersistentMap.from_mapping(...).

alter(f: Callable[[Any], Any], key: K) PersistentMap[K, V]
bimap(fk: Callable[[K], K2], fv: Callable[[V], V2]) PersistentMap[K2, V2]
contains_key(key: K) bool
delete(key: K) PersistentMap[K, V]
static empty() PersistentMap[Any, Any]
filter(predicate: Callable[[V], bool]) PersistentMap[K, V]
filter_with_key(predicate: Callable[[K, V], bool]) PersistentMap[K, V]
fold(f: Callable[[R, K, V], R], initial: R) R
static from_mapping(source: Mapping[K, V]) PersistentMap[K, V]
static from_pairs(pairs: Iterable[tuple[K, V]]) PersistentMap[K, V]
insert(key: K, value: V) PersistentMap[K, V]
is_empty() bool
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
keys_list() list[K]
lookup(key: K) Any | None
map_keys(f: Callable[[K], K2]) PersistentMap[K2, V]
map_values(f: Callable[[V], V2]) PersistentMap[K, V2]
static of_entries(*entries: tuple[K, V]) PersistentMap[K, V]
static singleton(key: K, value: V) PersistentMap[K, V]
to_list() list[tuple[K, V]]
union(other: PersistentMap[K, V]) PersistentMap[K, V]

Left-biased union: entries in self win on key collision.

Implemented as {**other._inner, **self._inner}: build other first, then overlay self → self values overwrite other on collision (left-biased). Pure C-speed, no Python-level loop.

values() an object providing a view on D's values
values_list() list[V]
class hydra.overlay.python.util.PersistentSet(_inner: frozenset[Any] | None = None, *, _internal: bool = False)

Bases: Set[T], Generic[T]

A persistent (immutable) ordered set backed by frozenset.

delete(element: T) PersistentSet[T]
difference(other: PersistentSet[T]) PersistentSet[T]
static empty() PersistentSet[Any]
filter(predicate: Callable[[T], bool]) PersistentSet[T]
static from_iterable(values: Iterable[T]) PersistentSet[T]
insert(element: T) PersistentSet[T]
intersection(other: PersistentSet[T]) PersistentSet[T]
is_empty() bool
map(f: Callable[[T], U]) PersistentSet[U]
member(element: T) bool
static of(*elements: T) PersistentSet[T]
static singleton(value: T) PersistentSet[T]
to_list() list[T]
union(other: PersistentSet[T]) PersistentSet[T]
static unions(sets: Iterable[PersistentSet[T]]) PersistentSet[T]