mutablenesting

This commit is contained in:
John Lancaster
2026-02-21 19:14:30 -06:00
parent 8d598ff135
commit 32ee15348b
2 changed files with 9 additions and 7 deletions

View File

@@ -2,26 +2,26 @@ from collections.abc import MutableMapping, MutableSequence, Sequence
from copy import copy
from typing import TypeVar
from .common import HookedContainer
from .common import HookedContainer, MutableNesting
from .sequence import HookedList
T = TypeVar("T")
class HookedMapping(HookedContainer[T], MutableMapping[T, T | MutableSequence[T] | MutableMapping]):
_data: MutableMapping[T, T | MutableSequence[T] | MutableMapping]
class HookedMapping(HookedContainer[T], MutableMapping[T, MutableNesting[T]]):
_data: MutableMapping[T, MutableNesting[T]]
def __init__(
self,
hook,
existing: MutableMapping[T, T | MutableSequence[T] | MutableMapping],
existing: MutableMapping[T, MutableNesting[T]],
path: Sequence[int] | None = None,
):
self.hook = hook
self._data = existing
self._path = list(path) if path is not None else []
def __getitem__(self, key: T) -> T | MutableSequence[T] | MutableMapping:
def __getitem__(self, key: T) -> MutableNesting[T]:
value = self._data[key]
match value:
case MutableMapping() as mapping:
@@ -35,7 +35,7 @@ class HookedMapping(HookedContainer[T], MutableMapping[T, T | MutableSequence[T]
case _ as item:
return item
def __setitem__(self, key: T, value: T | MutableSequence[T] | MutableMapping) -> None:
def __setitem__(self, key: T, value: MutableNesting[T]) -> None:
self._data[key] = value
if self.hook:
from . import events as e