types module
This commit is contained in:
@@ -2,7 +2,8 @@ from collections.abc import MutableMapping, MutableSequence
|
||||
from typing import TypeVar
|
||||
|
||||
from . import events as e
|
||||
from .container import HookedContainer, HookFunction, MutableNesting
|
||||
from .container import HookedContainer, MutableNesting
|
||||
from .events import HookFunction
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
@@ -46,7 +47,7 @@ class HookedMapping(HookedContainer[T], MutableMapping[T, MutableNesting[T]]):
|
||||
suppress_hook: bool = False,
|
||||
) -> MutableNesting[T] | None:
|
||||
new_path = self.new_path(key)
|
||||
event = e.SetItemEvent(new_path, value) if key in self._data else e.AddItemEvent(new_path, value)
|
||||
event = e.SetItemEvent(self, new_path, value) if key in self._data else e.AddItemEvent(self, new_path, value)
|
||||
match value:
|
||||
case HookedMapping(_data=value):
|
||||
self._data[key] = value
|
||||
@@ -59,4 +60,4 @@ class HookedMapping(HookedContainer[T], MutableMapping[T, MutableNesting[T]]):
|
||||
def __delitem__(self, key: T) -> None:
|
||||
item = self._data.pop(key)
|
||||
if self.hook:
|
||||
self.hook(e.RemoveItemEvent(self.new_path(key), item))
|
||||
self.hook(e.RemoveItemEvent(self, self.new_path(key), item))
|
||||
|
||||
Reference in New Issue
Block a user