reorder
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
from collections.abc import MutableMapping, MutableSequence, Sequence
|
||||
from collections.abc import MutableMapping, Sequence
|
||||
from copy import copy
|
||||
from typing import TypeVar
|
||||
|
||||
from . import events as e
|
||||
from .common import HookedContainer, MutableNesting
|
||||
from .sequence import HookedList
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
@@ -28,9 +27,9 @@ class HookedMapping(HookedContainer[T], MutableMapping[T, MutableNesting[T]]):
|
||||
new_path.append(key)
|
||||
match value:
|
||||
case MutableMapping() as mapping:
|
||||
return HookedMapping(hook=self.hook, existing=mapping, path=new_path)
|
||||
case MutableSequence() as seq:
|
||||
return HookedList(hook=self.hook, existing=seq, path=new_path)
|
||||
return HookedMapping(mapping, self.hook, path=new_path)
|
||||
case HookedContainer() as seq:
|
||||
return type(self)(seq, self.hook, path=new_path)
|
||||
case _ as item:
|
||||
return item
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ class HookedList(HookedContainer[T], MutableSequence[T]):
|
||||
) -> None:
|
||||
self.hook = hook
|
||||
match existing:
|
||||
case MutableSequence() as seq:
|
||||
self._data = seq
|
||||
case HookedContainer(_data=seq):
|
||||
self._data = seq
|
||||
case MutableSequence() as seq:
|
||||
self._data = seq
|
||||
case _ as it:
|
||||
self._data = list(it)
|
||||
self._path = list(path) if path is not None else []
|
||||
@@ -32,10 +32,10 @@ class HookedList(HookedContainer[T], MutableSequence[T]):
|
||||
new_path = copy(self._path)
|
||||
new_path.append(s)
|
||||
match self._data[s]:
|
||||
case MutableSequence() as seq:
|
||||
return type(self)(seq, self.hook, path=new_path)
|
||||
case HookedContainer(_data=seq):
|
||||
return type(self)(seq, self.hook, path=new_path)
|
||||
case MutableSequence() as seq:
|
||||
return HookedList(seq, self.hook, path=new_path)
|
||||
case _ as item:
|
||||
return item
|
||||
|
||||
|
||||
Reference in New Issue
Block a user