types module

This commit is contained in:
John Lancaster
2026-02-22 21:06:32 -06:00
parent 8eea62f403
commit 0c3dfde336
7 changed files with 55 additions and 47 deletions
+4 -3
View File
@@ -2,7 +2,8 @@ from collections.abc import MutableMapping, MutableSequence
from typing import TypeVar
from . import events as e
from .container import HookedContainer, HookFunction, MutableNesting
from .container import HookedContainer, MutableNesting
from .events import HookFunction
T = TypeVar("T")
@@ -46,7 +47,7 @@ class HookedMapping(HookedContainer[T], MutableMapping[T, MutableNesting[T]]):
suppress_hook: bool = False,
) -> MutableNesting[T] | None:
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(self, new_path, value) if key in self._data else e.AddItemEvent(self, new_path, value)
match value:
case HookedMapping(_data=value):
self._data[key] = value
@@ -59,4 +60,4 @@ class HookedMapping(HookedContainer[T], MutableMapping[T, MutableNesting[T]]):
def __delitem__(self, key: T) -> None:
item = self._data.pop(key)
if self.hook:
self.hook(e.RemoveItemEvent(self.new_path(key), item))
self.hook(e.RemoveItemEvent(self, self.new_path(key), item))