preserving internal mutable seqs
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user