home · contact · privacy
Split off UpdateMixin.static_copy into exportable IntoUpdateValue with better naming.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 11 Sep 2025 15:08:37 +0000 (17:08 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 11 Sep 2025 15:08:37 +0000 (17:08 +0200)
ircplom/client.py
ircplom/client_tui.py

index 500e98b3789f08d9b33e1887cffe8ecea5aedc73..f63d909c91891f56c9f43aaa1c23d3d7f94cc63d 100644 (file)
@@ -138,15 +138,10 @@ class _CompletableStringsList(_Clearable, _Completable):
         self.complete()
 
 
-class _UpdatingMixin(AutoAttrMixin):
-    _on_update: Callable
+class IntoUpdateValueMixin(AutoAttrMixin):
+    'Provides .into_update_value(), exportable for module-external consumers.'
 
-    def __init__(self, on_update: Callable, **kwargs) -> None:
-        super().__init__(**kwargs)
-        self._on_update = on_update
-
-    @property
-    def static_copy(self):
+    def into_update_value(self) -> Any:
         'Return non-updating copy of self.'
         if isinstance(self, _Dict):
             return None
@@ -165,6 +160,14 @@ class _UpdatingMixin(AutoAttrMixin):
                     else attr_val.static_copy)
         return obj
 
+
+class _UpdatingMixin(IntoUpdateValueMixin):
+    _on_update: Callable
+
+    def __init__(self, on_update: Callable, **kwargs) -> None:
+        super().__init__(**kwargs)
+        self._on_update = on_update
+
     def _make_attr(self, cls: Callable, key: str):
         return cls(on_update=lambda *steps: self._on_update(key, *steps))
 
index 1c0b1b79973e0f14aca12e0e803436d630e592d3..9183a8f4b1da4cd81a6cdf66e6459e97a5b9a801 100644 (file)
@@ -8,9 +8,9 @@ from typing import Any, Callable, Optional, Self, Sequence
 from ircplom.tui_base import (BaseTui, PromptWidget, TuiEvent, Window,
                               CMD_SHORTCUTS)
 from ircplom.client import (
-        AutoAttrMixin, Client, ClientQueueMixin, Dict, DictItem, IrcConnSetup,
-        LogScope, NewClientEvent, NickUserHost, ServerCapability,
-        SharedClientDbFields, Topic)
+        AutoAttrMixin, Client, ClientQueueMixin, Dict, DictItem,
+        IntoUpdateValueMixin, IrcConnSetup, LogScope, NewClientEvent,
+        NickUserHost, ServerCapability, SharedClientDbFields, Topic)
 
 CMD_SHORTCUTS['disconnect'] = 'window.disconnect'
 CMD_SHORTCUTS['join'] = 'window.join'
@@ -506,6 +506,6 @@ class _ClientKnowingTui(Client):
         value = ((parent[last_step] if last_step in parent.keys()
                   else None) if isinstance(parent, Dict)
                  else getattr(parent, last_step))
-        if value and hasattr(value, 'static_copy'):
-            value = value.static_copy
+        if isinstance(value, IntoUpdateValueMixin):
+            value = value.into_update_value()
         self._client_tui_trigger('update_db', update=_Update(path, value))