diff --git a/freedium-library/src/freedium_library/utils/utils/mutable_string.py b/freedium-library/src/freedium_library/utils/utils/mutable_string.py index 68c3666..b0bfe40 100644 --- a/freedium-library/src/freedium_library/utils/utils/mutable_string.py +++ b/freedium-library/src/freedium_library/utils/utils/mutable_string.py @@ -2,30 +2,21 @@ from typing import List, Union class MutableString: - __slots__ = ("_string", "_string_list", "_is_dirty") + __slots__ = ("_string", "_string_list") def __init__(self, string: Union[str, "MutableString"]) -> None: self._string: str = str(string) if isinstance(string, MutableString) else string self._string_list: List[str] = list(self._string) - self._is_dirty: bool = False @property def string(self) -> str: - if self._is_dirty: - self._string = "".join(self._string_list) - self._is_dirty = False - - return self._string - - def _mark_dirty(self) -> None: - self._is_dirty = True + return "".join(self._string_list) def __len__(self) -> int: return len(self._string_list) def pop(self, key: int) -> "MutableString": self._string_list.pop(key) - self._mark_dirty() return self def encode(self, encoding: str) -> bytes: @@ -35,12 +26,10 @@ class MutableString: if key < 0 or key > len(self._string_list): raise IndexError("string index out of range") self._string_list.insert(key, value) - self._mark_dirty() return self def __setitem__(self, key: Union[int, slice], value: str) -> None: self._string_list[key] = value - self._mark_dirty() def __getitem__(self, key: int) -> str: return self._string_list[key] @@ -55,4 +44,3 @@ class MutableString: if start < 0 or start >= len(self._string_list): raise IndexError("string index out of range") del self._string_list[start : start + length] - self._mark_dirty() diff --git a/freedium-library/src/freedium_library/utils/utils/test_mutable_string.py b/freedium-library/src/freedium_library/utils/utils/test_mutable_string.py index 132a8bb..8239a7e 100644 --- a/freedium-library/src/freedium_library/utils/utils/test_mutable_string.py +++ b/freedium-library/src/freedium_library/utils/utils/test_mutable_string.py @@ -17,13 +17,6 @@ def test_init(): assert str(ms3) == "" -def test_string_property(): - ms = MutableString("test") - ms._string_list[0] = "b" - ms._mark_dirty() - assert ms.string == "best" - - def test_len(): ms = MutableString("hello") assert len(ms) == 5