added suppress option

This commit is contained in:
John Lancaster
2026-02-22 20:55:59 -06:00
parent 05ba036346
commit 8eea62f403

View File

@@ -30,7 +30,7 @@ class HookedMapping(HookedContainer[T], MutableMapping[T, MutableNesting[T]]):
def __getitem__(self, key: T) -> MutableNesting[T]: def __getitem__(self, key: T) -> MutableNesting[T]:
if key not in self._data: if key not in self._data:
return self.__setitem__(key, {}) return HookedMapping(self.__setitem__(key, {}), hook=self.hook, path=self.new_path(key))
value = self._data[key] value = self._data[key]
match value: match value:
case MutableMapping() as mapping: case MutableMapping() as mapping:
@@ -38,7 +38,13 @@ class HookedMapping(HookedContainer[T], MutableMapping[T, MutableNesting[T]]):
case _ as item: case _ as item:
return item return item
def __setitem__(self, key: T, value: MutableNesting[T]) -> MutableNesting[T] | None: def __setitem__(
self,
key: T,
value: MutableNesting[T],
*,
suppress_hook: bool = False,
) -> MutableNesting[T] | None:
new_path = self.new_path(key) new_path = self.new_path(key)
event = e.SetItemEvent(new_path, value) if key in self._data else e.AddItemEvent(new_path, value) event = e.SetItemEvent(new_path, value) if key in self._data else e.AddItemEvent(new_path, value)
match value: match value:
@@ -46,7 +52,7 @@ class HookedMapping(HookedContainer[T], MutableMapping[T, MutableNesting[T]]):
self._data[key] = value self._data[key] = value
case _: case _:
self._data[key] = value self._data[key] = value
if self.hook: if self.hook and not suppress_hook:
self.hook(event) self.hook(event)
return value return value