From: Christian Heller Date: Thu, 11 Sep 2025 15:08:37 +0000 (+0200) Subject: Split off UpdateMixin.static_copy into exportable IntoUpdateValue with better naming. X-Git-Url: https://plomlompom.com/repos/reset_cookie?a=commitdiff_plain;h=97d2eec9617d39510253b23543c186afb463ba58;p=ircplom Split off UpdateMixin.static_copy into exportable IntoUpdateValue with better naming. --- diff --git a/ircplom/client.py b/ircplom/client.py index 500e98b..f63d909 100644 --- a/ircplom/client.py +++ b/ircplom/client.py @@ -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)) diff --git a/ircplom/client_tui.py b/ircplom/client_tui.py index 1c0b1b7..9183a8f 100644 --- a/ircplom/client_tui.py +++ b/ircplom/client_tui.py @@ -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))