diff --git a/src/python/jw/util/stree/StringTree.py b/src/python/jw/util/stree/StringTree.py index d196a28..df7e188 100644 --- a/src/python/jw/util/stree/StringTree.py +++ b/src/python/jw/util/stree/StringTree.py @@ -4,7 +4,7 @@ import fnmatch import re from collections import OrderedDict -from collections.abc import Mapping +from collections.abc import MutableMapping from enum import Enum, auto from typing import TYPE_CHECKING @@ -55,7 +55,7 @@ def cleanup_string(s: str | StringTree) -> str | StringTree: return s[1:-1].replace('\\' + s[0], s[0]) return s -class StringTree(Mapping): # export +class StringTree(MutableMapping): # export class Error(Exception): pass @@ -190,12 +190,16 @@ class StringTree(Mapping): # export raise self.Error(path) return ret - def __setitem__(self, key: str, value: str) -> StringTree: - return self.__set(key, value) + def __setitem__(self, key: str, value: str) -> None: + self.__set(key, value) def __iter__(self) -> Iterator[str]: return iter(self.children) + def __delitem__(self, key: str) -> None: + if key in self.children: + del self.children[key] + def __len__(self) -> int: return len(self.children) @@ -282,7 +286,7 @@ class StringTree(Mapping): # export def child_list(self, depth_first: bool = True) -> list[StringTree]: if not depth_first: - raise Exception( + raise self.Error( 'Tried to retrieve child list with breadth-first ' 'search, not yet implemented' )