InvalidatingDict#
- class eclypse.graph.invalidating_dict.InvalidatingDict[source]#
Bases:
dictDict that invalidates derived state when watched keys are mutated.
Methods
__init__(*args, on_change[, watched_keys])Initialize the dictionary with an invalidation hook.
clear()Remove all items and invalidate when the dictionary was non-empty.
pop(key[, default])Remove a key and invalidate when it existed.
popitem()Remove and return an item, then invalidate.
setdefault(key[, default])Set a default value and invalidate only when a key is inserted.
update(*args, **kwargs)Update values and invalidate when any watched value changes.
- __init__(*args, on_change, watched_keys=None, **kwargs)[source]#
Initialize the dictionary with an invalidation hook.
- Parameters:
*args (Any) – Initial dictionary data.
on_change (Callable[[tuple[Any, ...]], None]) – Callback invoked with changed watched keys.
watched_keys (Iterable[Any] | None) – Keys that trigger invalidation.
Nonewatches every key.**kwargs (Any) – Additional initial dictionary data.
- update(*args, **kwargs)[source]#
Update values and invalidate when any watched value changes.
- Parameters:
args (Any)
kwargs (Any)
- setdefault(key, default=None)[source]#
Set a default value and invalidate only when a key is inserted.
- Parameters:
key (Any)
default (Any)