pruning
This commit is contained in:
20
src/hooked_containers/mapping.py
Normal file
20
src/hooked_containers/mapping.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from collections.abc import Callable, MutableMapping, MutableSequence, Sequence
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
from . import events as e
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
class HookedMapping(Generic[T], MutableMapping[T, T | MutableSequence[T], MutableMapping[T]]):
|
||||
_data: MutableSequence[T]
|
||||
_path: MutableSequence[int]
|
||||
hook: Callable[[e.ChangeEvent[T]], None] | None
|
||||
|
||||
def __init__(self, hook, existing: MutableMapping[T], path: Sequence[int] | None = None):
|
||||
self.hook = hook
|
||||
self._data = existing
|
||||
self._path = list(path) if path is not None else []
|
||||
|
||||
def __setitem__(self, key):
|
||||
return
|
||||
@@ -1,6 +1,5 @@
|
||||
from collections.abc import Callable, Iterable, MutableSequence, Sequence
|
||||
from collections.abc import Iterable, MutableSequence, Sequence
|
||||
from copy import copy
|
||||
from enum import Enum, auto
|
||||
from typing import TypeVar
|
||||
|
||||
from . import events as e
|
||||
@@ -9,16 +8,8 @@ from .common import HookedContainer
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
class ListChange(Enum):
|
||||
ADD_ITEM = auto()
|
||||
REMOVE_ITEM = auto()
|
||||
SET_ITEM = auto()
|
||||
|
||||
|
||||
class HookedList(HookedContainer[T], MutableSequence[T]):
|
||||
_data: MutableSequence[T]
|
||||
_path: MutableSequence[int]
|
||||
hook: Callable[[e.ChangeEvent[T]], None] | None
|
||||
|
||||
def __init__(self, hook, existing: Iterable[T], path: Sequence[int] | None = None):
|
||||
self.hook = hook
|
||||
|
||||
Reference in New Issue
Block a user