reorg
This commit is contained in:
@@ -12,27 +12,30 @@ class HookedList(HookedContainer[T], MutableSequence[T]):
|
||||
_data: MutableSequence[T]
|
||||
path: MutableSequence[int]
|
||||
|
||||
def __init__(self, hook: HookFunction, existing: MutableSequence[T], path: MutableSequence[int] | None = None):
|
||||
def __init__(
|
||||
self,
|
||||
existing: MutableSequence[T],
|
||||
hook: HookFunction | None = None,
|
||||
path: MutableSequence[int] | None = None,
|
||||
) -> None:
|
||||
self.hook = hook
|
||||
match existing:
|
||||
case HookedContainer(_data=seq):
|
||||
self._data = seq
|
||||
case MutableSequence() as seq:
|
||||
self._data = seq
|
||||
case HookedContainer(_data=seq):
|
||||
self._data = seq
|
||||
case _ as it:
|
||||
self._data = list(it)
|
||||
self._path = list(path) if path is not None else []
|
||||
|
||||
def __getitem__(self, s):
|
||||
new_path = copy(self._path)
|
||||
new_path.append(s)
|
||||
match self._data[s]:
|
||||
case MutableSequence() as seq:
|
||||
new_path = copy(self._path)
|
||||
new_path.append(s)
|
||||
return type(self)(self.hook, existing=seq, path=new_path)
|
||||
return type(self)(seq, self.hook, path=new_path)
|
||||
case HookedContainer(_data=seq):
|
||||
new_path = copy(self._path)
|
||||
new_path.append(s)
|
||||
return type(self)(self.hook, existing=seq, path=new_path)
|
||||
return type(self)(seq, self.hook, path=new_path)
|
||||
case _ as item:
|
||||
return item
|
||||
|
||||
|
||||
Reference in New Issue
Block a user