set/add event

This commit is contained in:
John Lancaster
2026-02-22 19:04:00 -06:00
parent 977e87d7f5
commit 2efdf19ee1
2 changed files with 29 additions and 33 deletions

View File

@@ -15,6 +15,7 @@ class HookFunction(Protocol):
class HookedContainer(ABC, Sized, Iterable[T], Container[T]):
_data: MutableNesting[T]
_path: MutableSequence[int]
_root: MutableMapping[T] | MutableSequence[T] | None = None
hook: HookFunction
@@ -22,15 +23,21 @@ class HookedContainer(ABC, Sized, Iterable[T], Container[T]):
def __repr__(self):
return f"{self.__class__.__name__}({self._data!r})"
def __len__(self):
return len(self._data)
def __iter__(self):
return iter(self._data)
def __contains__(self, x):
return x in self._data
# Sequence Methods
# __contains__, __iter__, __reversed__, index, and count
@abstractmethod
def __getitem__(self, key): ...
def __len__(self):
return len(self._data)
# MutableSequence Methods
# append, reverse, extend, pop, remove, and __iadd__
@@ -44,8 +51,8 @@ class HookedContainer(ABC, Sized, Iterable[T], Container[T]):
if self.hook:
self.hook(e.RemoveItemEvent(self.new_path(s), item))
@abstractmethod
def insert(self, index, value): ...
# @abstractmethod
# def insert(self, index, value): ...
# Custom Methods