InvalidatingDict#

class eclypse.graph.invalidating_dict.InvalidatingDict[source]#

Bases: dict

Dict 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. None watches 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)

pop(key, default=<object object>)[source]#

Remove a key and invalidate when it existed.

Parameters:
  • key (Any)

  • default (Any)

popitem()[source]#

Remove and return an item, then invalidate.

clear()[source]#

Remove all items and invalidate when the dictionary was non-empty.