From fcc8ad68aebc85fb9a841e43770d0bf3cd2ffaaf Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 21 Feb 2026 18:43:33 -0600 Subject: [PATCH] preserving internal mutable seqs --- src/hooked_containers/list.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/hooked_containers/list.py b/src/hooked_containers/list.py index f4b9406..4f04d55 100644 --- a/src/hooked_containers/list.py +++ b/src/hooked_containers/list.py @@ -1,4 +1,4 @@ -from collections.abc import Callable, Iterable, MutableSequence +from collections.abc import Callable, Iterable, MutableSequence, Sequence from dataclasses import dataclass from enum import Enum, auto from typing import Generic, TypeVar @@ -33,11 +33,17 @@ class RemoveItemEvent(ListChangeEvent[T]): class HookedList(Generic[T], MutableSequence[T]): - _data: list[T] + _data: MutableSequence[T] + _path: MutableSequence[int] hook: Callable[[ListChangeEvent[T]], None] | None - def __init__(self, iterable: Iterable[T], hook=None): - self._data = list(iterable) + def __init__(self, iterable: Iterable[T], path: Sequence[int] | None = None, *, hook=None): + match iterable: + case MutableSequence() as seq: + self._data = seq + case Iterable() as it: + self._data = list(it) + self._path = list(path) if path is not None else [] self.hook = hook def __repr__(self):