home · contact · privacy
Move _Update.value adaption into class proper.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 11 Sep 2025 14:58:46 +0000 (16:58 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 11 Sep 2025 14:58:46 +0000 (16:58 +0200)
ircplom/client_tui.py

index ba1b29578bd0dac7bc87e1f65dbf386b4fe12733..1c0b1b79973e0f14aca12e0e803436d630e592d3 100644 (file)
@@ -1,7 +1,7 @@
 'TUI adaptions to Client.'
 # built-ins
 from getpass import getuser
-from dataclasses import dataclass, asdict as dc_asdict
+from dataclasses import asdict as dc_asdict
 from types import get_original_bases
 from typing import Any, Callable, Optional, Self, Sequence
 # ourselves
@@ -25,10 +25,14 @@ _LOG_PREFIX_OUT = '>'
 _LOG_PREFIX_IN = '<'
 
 
-@dataclass
 class _Update:
-    path: tuple[str, ...]
-    value: Optional[Any] = None
+
+    def __init__(self, path: tuple[str, ...], value: Any) -> None:
+        self.path = path
+        for cls in [cls for cls in _UPDATING_DATACLASSES
+                    if isinstance(value, get_original_bases(cls)[1])]:
+            value = cls(**dc_asdict(value))
+        self.value = value
 
     @property
     def key(self) -> str:
@@ -350,10 +354,6 @@ class _ClientWindowsManager:
 
     def update_db(self, update: _Update) -> bool:
         'Apply update to .db, and if changing anything, log and trigger.'
-        for cls in [cls for cls in _UPDATING_DATACLASSES
-                    if isinstance(update.value, get_original_bases(cls)[1])]:
-            update.value = cls(**dc_asdict(update.value))  # type: ignore
-            break
         result = self.db.recursive_set_and_report_change(update)
         if result is None:
             return False