nested
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from collections.abc import Callable, MutableSequence
|
||||
from collections.abc import Callable, Iterable, MutableSequence
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum, auto
|
||||
from typing import Generic, TypeVar
|
||||
@@ -36,8 +36,8 @@ class HookedList(Generic[T], MutableSequence[T]):
|
||||
_data: list[T]
|
||||
hook: Callable[[ListChangeEvent[T]], None] | None
|
||||
|
||||
def __init__(self, *args, hook=None, **kwargs):
|
||||
self._data = list(*args, **kwargs)
|
||||
def __init__(self, iterable: Iterable[T], hook=None):
|
||||
self._data = list(iterable)
|
||||
self.hook = hook
|
||||
|
||||
def __repr__(self):
|
||||
@@ -53,8 +53,15 @@ class HookedList(Generic[T], MutableSequence[T]):
|
||||
return len(self._data)
|
||||
|
||||
def __getitem__(self, s):
|
||||
print("Getting item:", s)
|
||||
return self._data[s]
|
||||
# print("Getting item:", s)
|
||||
match self._data[s]:
|
||||
case HookedList() as hs:
|
||||
hs.hook = self.hook
|
||||
return hs
|
||||
case MutableSequence() as seq:
|
||||
return HookedList(seq, hook=self.hook)
|
||||
case _ as item:
|
||||
return item
|
||||
|
||||
def __setitem__(self, s, value):
|
||||
self._data[s] = value
|
||||
|
||||
Reference in New Issue
Block a user