From cea2d9a58d4aba40c537fbef3c1e5f3966a32d54 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Thu, 11 Sep 2025 22:20:27 +0200 Subject: [PATCH] Simplify CompletableTopic. --- ircplom/client.py | 42 ++++++++++-------------------------------- ircplom/client_tui.py | 2 +- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/ircplom/client.py b/ircplom/client.py index b404218..bd6ad5b 100644 --- a/ircplom/client.py +++ b/ircplom/client.py @@ -7,7 +7,7 @@ from enum import Enum, auto from getpass import getuser from threading import Thread from typing import (Any, Callable, Collection, Generic, Iterable, Iterator, - NamedTuple, Optional, Self, Set, TypeVar) + Optional, Self, Set, TypeVar) from uuid import uuid4 # ourselves from ircplom.events import ( @@ -204,11 +204,9 @@ class IntoEndnodeUpdatesMixin(AutoAttrMixin): def into_endnode_updates(self, path: tuple[str, ...] ) -> list[tuple[tuple[str, ...], Any]]: 'Return path-value pairs for any update-worthy sub-elements.' - if isinstance(self, _CompletableStringsCollection): + if isinstance(self, _Completable): return ([(path, self._completed)] if self._completed is not None else []) - if isinstance(self, _CompletableTopic): - return [(path, Topic(*self._completed))] updates = [] for key, val in (self._dict.items() if isinstance(self, Dict) else ((k, getattr(self, k)) @@ -326,7 +324,8 @@ class ServerCapability: enabled: bool = False -class Topic(NamedTuple): +@dataclass +class Topic: 'Collects both setter and content of channel topic.' what: str = '' who: Optional[NickUserHost] = None @@ -376,35 +375,14 @@ class _IrcConnection(BaseIrcConnection, _ClientIdMixin): client_id=self.client_id).kw(e=e) -class _CompletableTopic(_Completable): - _what: str = '' - _who: Optional[NickUserHost] = None - - def __init__(self) -> None: - self._completed: tuple[str, Optional[NickUserHost]] = ('', None) - - @property - def what(self) -> str: - 'Content of topic.' - return self._what - - @what.setter - def what(self, what: str) -> None: - self._what = what - - @property - def who(self) -> Optional[NickUserHost]: - 'Setter of topic.' - return self._who - - @who.setter - def who(self, who: NickUserHost) -> None: - copy = _NickUserHost.from_str(str(who)) - self._who = NickUserHost(copy.nick, copy.user, copy.host) +class _CompletableTopic(_Completable, Topic): + _completed: Optional[Topic] = None def complete(self) -> None: - self._completed = (('', None) if self._who is None - else (self._what, self._who)) + assert self.who is not None + copy = _NickUserHost.from_str(str(self.who)) + self._completed = Topic(self.what, + NickUserHost(copy.nick, copy.user, copy.host)) class _Channel: diff --git a/ircplom/client_tui.py b/ircplom/client_tui.py index 1a96377..f1d5e90 100644 --- a/ircplom/client_tui.py +++ b/ircplom/client_tui.py @@ -217,7 +217,7 @@ class _QueryWindow(_ChatWindow): class _UpdatingChannel(_UpdatingNode): user_ids: set[str] - topic: Topic = Topic() + topic: Topic log_scopes = {'': LogScope.CHAT} def _focused_set_and_report_change( -- 2.30.2