From cd3679cbd759ea725c22951a148f6a8c2059c6cc Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 21 Feb 2026 18:35:37 -0600 Subject: [PATCH] nested --- src/hooked_containers/list.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/hooked_containers/list.py b/src/hooked_containers/list.py index 6214e5a..f4b9406 100644 --- a/src/hooked_containers/list.py +++ b/src/hooked_containers/list.py @@ -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